I recently tried to install a couple of python modules via easy_install on my mac.
Background:
I'm using OS X 10.6.8 and Python 2.7.2. If I run which python I get the following:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Problem:
If I try to install a package, say easy_install cssutils - it finds the package, downloads and says it's installed, but when I then open python and type import cssutils - it says the package isn't found.
This has happened with multiple packages, but they do however work if the package has it's own installer script and I run that.
How can I get easy_install to install the packages correctly?
Typing:
head -1 `which easy_install`
at the command line will show the interpreter that easy_install is using. If it doesn't match the python version you're using, you may need to install setup tools for the version of python you're using. Alternately, if the correct version of easy install is present, you can either run it by using an absolute path, reference the specific easy_install variant (e.g. easy_install-2.7), or update your path.
Related
I've installed the module pyaudio using pip. However, when I try to import it, Python says the module is not found:
C:\Users\hp>pip install pyaudio
Requirement already satisfied: pyaudio in c:\users\hp\appdata\local\programs\python\python37\lib\site-packages (0.2.11)
>>> import pyaudio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyaudio'
Why can't Python find the installed module?
(I am using Python 3.7.)
It happens quite often that someone installs a Python package using pip, but then can't seem to import it in Python. To understand why this happens, you must know how Windows finds executables to run, and how the Python software is installed. The basics:
When running a command, Windows searches for an executable in the environment variable PATH. It executes the first one found.
The Python interpreter, python.exe, is installed in <PYTHON_INSTALL_DIR> (e.g. C:\Python\3.7).
Python tools such as pip, pylint, virtualenv, PyCrust, etc., are installed in <PYTHON_INSTALL_DIR>\Scripts.
The Python launcher for Windows, py.exe, is installed in your Windows system directory (e.g. C:\Windows).
python and pip commands use the modules found in the directory their installed in, they do not look at PATH.
So, let's say you have the following Python versions:
C:\Python\2.7
C:\Python\3.6
C:\Python\3.7
and your PATH environment contains the following directories:
C:\Python\2.7
C:\Python\3.6\Scripts
then, see the following output:
C:\>python -V
Python 2.7.16
C:\>pip -V
pip 19.1.1 from c:\python\3.6\lib\site-packages\pip (python 3.6)
C:\>py -V
Python 3.7.3
So, when running pip, it is possible that the packages are installed in another Python version then the version you'll get when running python.
To see which versions are (correctly) installed on your system, run py -0p. Example output:
C:\>py -0p
Installed Pythons found by py Launcher for Windows
-3.7-64 C:\Python\3.7-64\python.exe *
-3.7-32 C:\Python\3.7-32\python.exe
-3.6-64 C:\Python\3.6-64\python.exe
-2.7-64 C:\Python\2.7-64\python.exe
-2.7-32 C:\Python\2.7-32\python.exe
General solution (for Windows)
The best thing is not to rely on your system PATH. Use the py launcher to select the version you want. To run the pip module corresponding to the Python version you want to use, start pip as a module instead of executable.
So instead of:
pip install <package>
run:
py -3.6 -m pip install <package>
To see which Python packages you have installed for that Python version, use:
py -3.6 -m pip freeze
Some additional remarks
Whether a Python installation is added to your PATH or not, is an option during the installation. If it is added, it is added at the beginning of the PATH, so the most recently installed Python version will be selected first.
The Windows system directory should always be in your PATH, so the py command will always be available, even if you did not add any Python installation to your PATH.
If you double-click on a .py file from Windows Explorer, or type the filename directly as a command in a Command Prompt (e.g. test.py), then the action is determined from the Windows registry. It is possible that the file will be opened in your IDE, or that it's executed using a Python interpreter. In that case, it is probably the most recently installed Python version. It's possible that the command python test.py, uses a different Python version than the command test.py.
Some installations also include executables named python2/python3 (not on Windows), pip3/pip3.7 (also on Windows), etc. This would also allow you to specify which version to use. These would be useful on systems where these binaries exist and are in the path.
You'd think python -m pip install pyaudio would solve the problem but it does not.
To install pyaudio you'd first need to install pipwin using:
pip install pipwin
pipwin is a complementary tool for pip on Windows. pipwin installs unofficial python packages.
Next, use pipwin to install pyaudio,
pipwin install pyaudio
I issue a command to install scipy see below
PS C:\Users\yosief\Downloads> pip install .\scipy-0.16.1-win32-superpack-python3.4.exe
and I get an error-traceback
Invalid requirement: '.\scipy-0.16.1-win32-superpack-python3.4.exe'
It looks like a path. Does it exist?
My ENV variable is set so I can issue pip install from
C:\Users\yosief\Downloads>
even though my python path is:
C:\Users\yosief\AppData\Local\Programs\Python\Python36-32
Thanks
There might be nothing wrong with the file path. Your problem is with the package you are attempting to install.
This will fail because You are running Python 3.6 and you are attempting to install a Python 3.4 package.
You have three options to fix this problem:
1) Just try pip install and the package name you want. No need to download first it does it for you!
OR:
2) Get the correct file. From what I see you are running it should be a 32bit Windows 3.6 (or 36) version package. Everything must match
3) If you can't find your version but the package is Python 3 supported you can download the source and run python setup.py install and it should install.
When I run python -V from terminal, I see that Python 2.7.10 is installed. I want to keep this as the "global" version as OSX utilizes it.
When I run Idle, I see that Python 3.6.0 is running. How do I install libraries to this version of Python?
For example, if I run pip install bs4, the library is installed here beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.5.3-py2.7.egg - which is obviously Python 2.7.
So when I run my script from Idle, I get the following error:
ModuleNotFoundError: No module named 'bs4'
You want to use virtualenv. It sounds like you have two versions of Python installed and you need to focus on one while being able to manage the packages in each. Virtualenv will do this for you.
First install virtualenv (https://virtualenv.pypa.io/en/stable/),
Second run it specifying the version of python you want as so: `virtualenv -p /usr/bin/python2.6
Third you can use pip to install packages directly into this environment. This increases the amount of disk space you need, but will allow you greater control over your code.
When you have two versions of python, you will need to specify which version of python you would like to run. You can do this with the activate command. For example:
activate python3
Once you have activated the python 3 environment, you can then run pip:
pip3 install bs4
which will install the beautiful soup library in your python 3 environment.
Another answer was found here: https://stackoverflow.com/a/4910393/1580659
pipVERSIONNUMBER install will install the library to the correct version of Python.
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
I have both Python 2.7 and Python 3.4 (and have to have both because for the class I'm running, students have the option of using either). One student has used Python 2.7 and numpy for their project, but when I attempt to install numpy, it installs it to 3.4. I need to install it to 2.7.
I'm using numpy 1.9 from this site, which I'm told is also 2.7-specific: http://sourceforge.net/projects/numpy/files/NumPy/
However, nonetheless it still goes to the 3.4 folder. Copying it to Python 2.7 didn't work, obviously.
How do I do this?
I recommend installing with pip.
pip install numpy
If this doesn't work on windows then download the binary from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and convert it to a wheel before installing.
pip install wheel
wheel convert path/to/binary
pip install numpy_wheel
Pip is recommended because you can uninstall.
To check where you are installing to
pip -V
You may have an environmental variable path to the wrong pip.
Assuming that you are using, or at least you should use pip to install the library. You can specify the python version to be installed by changing the suffix, e.g. pip-2.7 install numpy.
pip install numpy
pip-2.7 install numpy
pip-3.4 install numpy
As an alternative, in case that you do not want to use pip is to download and install the library using setup with a similar technique.
python setup.py install
python2.7 setup.py install
python3.4 setup.py install
Your PATH isn't setup correctly.
C:> where pip
Should tell you which pip it is trying to use, and it is likely whichever one it found on your PATH first...
So, instead, you will want to run it as
C:> C:\mypython2install\pip.exe install numpy
Or, setup your path correctly. See here
Just one other note on issues like this. I had a similar problem with Python 2.7 libraries not being found, because I had miniconda installed for a Python virtual environment that was hijacking calls to python from other programs. After deleting the minconda directory in my home the problem went away and python libraries that were properly installed were found again.
Note-This answer is particularly for Windows PC which has both Python2 & Pyhton3 installed on it.
Both the versions of Python has their different directories somewhat like
"C:\Python27\" ----for python2
"C:\Python35\" ---- for python3
*(or it depends on what path you chose while installing Python**)*
pip GENERALLY exist under the directory "C:\Python**\Scripts"
there you can find exe files like:
pip.exe/pip2.exe/pip2.7.exe ----for python2
pip3.exe/pip3.5.exe ----for python3
to install packages on python2:
use
Python27\Scripts\pip2.exe install package_name
(where the 1st argument is the path of exe file, it might differ for your system)
to install packages on python3:
use
Python35\Scripts\pip3.exe install package_name
there is no need to uninstall any version of python to achieve the task.
I'm using ubuntu 12.10 with default python3.2. However I downloaded python 3.3 as its much more polished. Of course, since then I have a nightmare with installing modules for 3.3, as python3 packages from synaptic install to 3.2 dir. So, I installed pip using python 3.3. Now I have pip-3.3 command, great. But, when I tried "sudo pip-3.3 install PySide" I quickly got an error: "error: Failed to locate the Python library /usr/lib/libpython3.3m.so". What's more, when I run "sudo pip install PySide" (command for 2.7), it builded and installed and runs flawlessy. Pyvenv and virtualenv both fail too. But I wan't to do it non-env way,just install pyside to global 3.3 lib dir.
So how can I install that PySide to python 3.3? I just can't get it to work... It looks like I will have to stick with default ubuntu python 3 version (this one runs great, everything works both from pip and synaptic), but I like to use newest python as it gets better and better with every release.
Btw, if that matters I also got following warning before that error:
"package init file 'PySide/init.py' not found (or not a regular file)" and
"package init file 'pysideuic/init.py' not found (or not a regular file)"
Edit: I installed full python3.3 from synaptic, including pythoh3.3-dev, debug, lib etc. Everything.
And that dynamic python 3.3 lib exist in /usr/lib/x86_64-linux-gnu/libpython3.3m.so, maybe just python3.3 package for ubuntu is poor and installs it in wrong direction/doesn't do any symlinks tricks?
Please try this answer installing from source (PySide). Download pyside sources and install from source, follow the instructions on the link.