Ways of installing python module - python

I'm new to python, about a month.
I know installing python modules can be done by using pip or easy_install. But when I was trying to install the regex module it gave me an error.
Typing pip install re in cmd gave me the following errors;
ERROR: Could not find a version that satisfies the requirement re (from versions: none)
ERROR: No matching distribution found for re
So I went to PyPI and downloaded a file there and now PyCharm doesn't give error when I import the module anymore.
So are there any difference between these ways of downloading Python modules or it doesn't matter ?
I'm using Windows 10 and have Python 3.8 and 3.8.1.

re is a built-in module, therefore you are not required to install this with pip.
Python Built-In Modules

re is part of the Python standard library so there is no need to install it separately. There are many ways to 'install' a package, e.g. using easy_install, pipx, venv, poetry, etc., but pip install --user is likely the way you're going to want to go to get started until you run into a compelling reason to explore other options. Either way, all these tools are essentially just various ways to move packages into PYTHONPATH, the place that Python looks for packages by default.

Related

Can't import ijson module on python 3.7.0

I have installed python 3.7.0 and my installation directory is AppData\Local\Programs\Python\Python37-32
Now I have tried to upgrade pip with:
python -m pip install –upgrade pip'
and I got:
Successfully installed pip-19.0.3
I did pip install ijson(while I was in folder AppData\Local\Programs\Python\Python37-32\Scripts) and double checked with the result being:
Requirement already satisfied: ijson in c:\users\myusername\appdata\local\programs\python\python37-32\lib\site-packages (2.3)
But when I go to my PyCharm project and I import ijson it can't find the module.Just to be clear if I import json or any other module I can work with it.
I know this has some duplicates and I have seen some of them. I have tried everything for example on these and others. Just for reference (possible duplicate)(possible dublicate 2)
but I haven't been able to solve my issue. Please tell me if I am missing something, maybe it is connected to the interpreter I am using or a wrong installion of python.
Thank you in advance
Make sure the python interpreter you are using in Pycharm is the one where you install ijson via pip.
You can do this by looking at the interpreter path in PyCharm, then opening that path in your terminal and trying import ijson
Also make sure the pip you are using is connected to the python interpreter you are using in PyCharm

Python pip install gives “Command ”python setup.py egg_info“ failed with error code 1”

Edit: Yes I know this question already exists, except my question is a bit different and none of the solutions fixed it.
I do most of my Python stuff when I'm at work and not on my personal machine, but I decided to install it on my personal computer as well. I fresh installed python 3.6.1, and created a virtual environment with virtualenv. Then within the virtualenv I tried to pip install urllib (or any module) and I received the error:
(pdbot) C:\Users\user\Documents\pdbot>pip install urllib
Collecting urllib
Using cached urllib-1.21.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\setup.py", line 191
s.connect((base64.b64decode(rip), 017620))
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I read elsewhere that this error had something to do with setuptools not being properly installed. So I ran this to attempt to fix the issue:
easy_install -U setuptools
I ended up receiving an even weirder error next:
(pdbot) C:\Users\zeke\Documents\pdbot>easy_install -U setuptools
Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Downloading https://pypi.python.org/packages/a9/23/720c7558ba6ad3e0f5ad01e0d6ea2288b486da32f053c73e259f7c392042/setuptools-36.0.1.zip#md5=430eb106788183eefe9f444a300007f0
Best match: setuptools 36.0.1
Processing setuptools-36.0.1.zip
Writing C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\setup.cfg
Running setuptools-36.0.1\setup.py -q bdist_egg --dist-dir C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\egg-dist-tmp-8apak7kn
warning: no files found matching '*' under directory 'setuptools\_vendor'
Copying setuptools-36.0.1-py3.6.egg to c:\users\zeke\documents\pdbot\lib\site-packages
Adding setuptools 36.0.1 to easy-install.pth file
Installing easy_install-script.py script to c:\users\zeke\documents\pdbot\Scripts
Installing easy_install.exe script to c:\users\zeke\documents\pdbot\Scripts
error: [WinError 5] Access is denied: 'c:\\users\\zeke\\documents\\pdbot\\Scripts\\easy_install.exe'
This looks like a permissions error, but I ran these both in an administrator command prompt (Windows 10) and got the same result. I am the only user on this computer and I have all admin permissions. Is this virtualenv causing an issue? How do I remedy it?
EDIT: I was able to fix the permissions issue by leveraging the python executable like so:
python -m easy_install -U setuptools
But it didn't fix the python setup.py egg_info issue. I still get this error message when trying to pip install anything:
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I have tried both python -m pip install urllib and pip install urllib and neither work.
I had the same problem when trying to install urllib, but after doing a pip search urllib, I discovered that the problem was due to the version of urllib. From the search:
$ pip search urllib
...
> urllib5 (5.0.0) - Just increment the number and create a new lib. Never fix the original one.
At the end, a simple
pip install urllib5
within an elevated shell solved it.
Your problem has to do with permissions. The related/similar tools setup_tools, easy_install, and pip all tend to set a default set of permissions on files and folders they try to create in the package installation folder(s), rather than trying to match access permissions of the location they're installing in.
On Linux systems, where files and folders individually have permissions, this is frequently bypassed with the sudo command. On Windows, the equivalent is to run the installer as an Administrator. Since you're in the console, you have to open a console with Administrator privileges to run the pip command in.
Notable under Windows, the modules installed with pip from an Administrator console are still accessible to all users of the system that have the proper path in the PYTHONPATH system environment variable. Under Linux however, the problem is exacerbated by the fact that the files themselves may not be created with read and execute access for other users and may need to have their permissions manually modified after installation.
WARNING: urllib vs urllib2 vs urllibx
Both other answers claim that the problem is you're not specifying the correct "version" of the module in the call to pip. Neither is correct, as the error clearly indicates an installation folder access permissions violation causing the failure, but they also incorrectly recommended VERY unsafe behavior.
pip install urllib != pip install urllib5 these are two completely different packages.
The documentation for pip (https://packaging.python.org/tutorials/installing-packages/#id17) clearly says the way to specify a module version explicitly is pip install 'urllib==5'.
As part of how the package management engine implemented by pip works, running the command pip install urllib will always try to use the latest version of the urllib package, so you shouldn't need to specify the version unless you have some reason that you need a very specific version of the module.
There are two points to make in order to answer your question:
1. You are lucky you did not install that package!
The package you were trying to install was a maliciously created python package that was designed to look like a real package (in this case urllib3). If you had installed it, the package would have operated as normal except it would have sent some basic information about the system on which you installed the package to a URL (you can see more details on this here). You can read more about this fake package at either of the following links:
https://app.threatconnect.com/auth/incident/incident.xhtml?incident=5256822&owner=Common%20Community (you can sign up for a free account to view this one)
http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/index.html
Sending basic information about your systems to an unknown source isn't the worst thing you could do, but is certainly something you want to avoid when possible.
2. To properly install a package...
Specifically urllib:
To install urllib, you need to specify the version of the package you would like to install. For example, pip install urllib3.
Any package in general:
As #Elisabete Coelho suggested, you can use the pip search <package-name> feature to view the available packages. This is not perfect, however, as it may list malicious libraries like the one you were trying to install. A good guideline is that you should follow the installation instructions in a package's documentation closely to avoid any unforeseen issues. This is just an unfortunate necessity of living in a world where people make pretend python packages.

Why are different python modules installed in different locations?

I just found something strange and don't know how to fix it. I found a kludge of a workaround though but would rather not do this if I can help it.
I am working on a MBP 10.9.5. I upgraded pip to 9.0.1 from 8.0.1. Then I installed three modules (four if you count the required module)
image
pillow
py2app (required macholib, which it installed automatically)
After the modules are installed, I run pip show on them to see what the locations are.
For some reason, image, pillow and macholib are all installed at
/usr/local/lib/python2.7/site-packages
whereas py2app is installed at
/Library/Python/2.7/site-packages
Do we know why python is splitting up where the modules are installed? The workaround is to go into /usr/local/lib/python2.7/site-packages and copy the directories of these modules to /Library/Python/2.7/site-packages. However, I'd like to avoid doing this if possible and tell pip to install everything in one location rather than wherever it feels like.
There are no config files found for pip (I can list the dirs I looked at if needed) and if there are secret hidden config files, that doesn't explain why pip is installing module files to multiple locations.
Can anyone tell me why this is happening and how to stop it from happening?
Thanks
If /usr/local/lib/python2.7/site-packages is not in your sys.path when you start python, you could find the file named sitecustomize.py in the python library directory and add (as super user) the following lines
import site
site.addsitedir('/usr/local/lib/python2.7/site-packages')
in this file. It should solve the problem.

python-docx cannot be imported to python

I'm trying to install python-docx so I typed in the cmd
easy_install python-docx
and got:
Searching for python-docx
Best match: python-docx 0.7.4
Processing python_docx-0.7.4-py2.6.egg
python-docx 0.7.4 is already the active version in easy-install.pth
Using c:\python26\lib\site-packages\python_docx-0.7.4-py2.6.egg
Processing dependencies for python-docx
Finished processing dependencies for python-docx
but when I open python and type:
import docx
I got:
File "c:\python26\lib\site-packages\docx-0.2.4-py2.6.egg\docx.py", line 17, in <
module>
from lxml import etree
ImportError: DLL load failed: The specified procedure could not be found.
How can I solve this import error? what is missing?
This symptom can arise when you have both a legacy version and a new version of python-docx installed. I recommend you uninstall both completely and then install python-docx using pip. In general I recommend avoiding the use of easy_install anymore.
The legacy versions (v0.2.x) have the install-package name 'docx'. The new version uses the name 'python-docx' (although both import as 'docx' once installed). If you installed with pip doing the uninstall/reinstall would look something like this:
$ pip freeze
...
docx
...
python-docx
...
$ pip uninstall docx
...
$ pip uninstall python-docx
...
$ pip install python-docx
...
It sounds like you used easy_install originally, so you might need to uninstall manually, although I would try first and see if pip will get it done for you. If not, a quick search on python easy_install uninstall will lead you to useful resources. It might involve visiting "c:\python26\lib\site-packages\" and removing any files or directories that start with 'docx' or 'python-docx'.
This should get you further along. If it still gives you trouble after doing this, let me know the new symptoms. You should be able to install pretty transparently on an uncorrupted Python installation if you use pip.
I too was getting same 'DLL load failed' error. Stupid mistake on my part, but had installed 32 bit Python on to 64 bit Windows. Un-installed 32 bit version, installed 64 bit version - problem sorted.

Installing scikits.bvp_solver

I need to use scikits.bvp_solver in python.
I currently use Canopy as my standard Python interface, where this package isn't available. Is there another available package for solving boundary value problems? I have also tried downloading using macports but the procedure sticks when it tries building gcc48 dependency.
You can try to download the package tar.gz and use easy_install . Or you can unpack the package and use the standard way of python setup.py install. I believe both ways require a fortran compiler.

Categories