Python3找不到pip3安装的模块
我在使用python3时遇到问题.由于某些原因,我无法弄清楚,python3中可用的模块与通过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.
在终端中运行pip3 list
会返回:
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)
运行此脚本,以查看python3
有哪些模块可用的返回值:
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']
这两个不一样,我不知道为什么.例如,nltk
具有较旧的版本. pandas
丢失.
These two are not the same and I can't tell why. nltk
, for example, has an older version. pandas
is missing.
我已经通过自制软件安装了python,并且正在通过Textmate2运行脚本.但是,当我通过python3
在终端中运行代码时,我遇到了同样的问题. pip3和python3都安装在/usr/local/bin/
中:
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
这也是python3使用的版本:
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.
查看pip3
脚本的第一行.
第一行(以#!
开头)应指向与python 3的符号链接相同的可执行文件.
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
如果不是这种情况,请卸载pip
并使用正确的Python版本再次安装.
If this is not the case, deinstall pip
and install it again with the correct Python version.
编辑:
如果您确实要确保您在pip
上使用了正确的Python,则可以将其作为这样的模块调用:
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
如果收到错误No module named pip
,则说明该版本的python未安装pip
.
If you get the error No module named pip
, then pip
is not installed for this version of python.