Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 does not find modules installed by pip3

I'm having problems with python3. For some reason that I cannot figure out, the modules available in python3 are not the same as the ones installed via pip3.

Running pip3 list in a Terminal returns:

DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
nltk (3.2.2)
numpy (1.12.0)
pandas (0.19.2)
pip (9.0.1)
python-dateutil (2.6.0)
pytz (2016.10)
setuptools (25.2.0)
six (1.10.0)
wheel (0.29.0)

Running this script to see what modules python3 has available returns:

 ['cycler==0.10.0', 'matplotlib==1.5.3', 'nltk==3.2.1', 'numpy==1.11.2', 'pip==9.0.1', 'pyparsing==2.1.10', 'python-dateutil==2.6.0', 'pytz==2016.7', 'setuptools==18.2', 'six==1.10.0']

These two are not the same and I can't tell why. nltk, for example, has an older version. pandas is missing.

I've installed python via homebrew and I'm running scripts via Textmate2. However, I have the same problem when I run code in terminal, via python3. Both pip3 and python3 are installed in /usr/local/bin/:

$ which python3 pip3
/usr/local/bin/python3
/usr/local/bin/pip3

And that's also the version python3 is using:

>>> import sys, os
>>> os.path.dirname(sys.executable)
'/usr/local/bin'

If someone could help me figure out why this is the case, and how I can fix it, I would very much appreciate the help.

like image 882
altabq Avatar asked Feb 17 '17 17:02

altabq


People also ask

Why can't Python find my module?

This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.

Why pip install module not found?

The Python "ModuleNotFoundError: No module named 'pip'" occurs when pip is not installed in our Python environment. To solve the error, install the module by running the python -m ensurepip --upgrade command on Linux or MacOS or py -m ensurepip --upgrade on Windows.

How do I fix pip3 not found?

To Solve sudo: pip3: command not found Error Just use python3 -m pip and this solved my problem. Second solution is Just check pip installed or not with this command pip3 -V If pip is not installed then You would need to install pip3. For Linux Users sudo apt install python3-pip.


1 Answers

Look at the first line of the pip3 script.

The first line (starting with #! should point to the same executable as the symbolic link for python 3:

> head -n 1 /usr/local/bin/pip
#!/usr/local/bin/python3.6

> ls -ld /usr/local/bin/python3
lrwxr-xr-x  1 root  wheel  9 Dec 25 22:37 /usr/local/bin/python3@ -> python3.6

If this is not the case, deinstall pip and install it again with the correct Python version.

EDIT:

If you really want to make sure that you're using the the right Python with pip, then call it as a module like this:

python3.7 -m pip list

If you get the error No module named pip, then pip is not installed for this version of python.

like image 92
Roland Smith Avatar answered Oct 14 '22 04:10

Roland Smith