简体   繁体   中英

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.

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.

I ran to this problem in Windows. first of all I uninstall the package using cmd command pip3 uninstall moduleName . Then based on python documentation I run command python -m pip install moduleName and my problem solved!

Here is the documentation: Installing Python Modules

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM