简体   繁体   English

Python3 找不到 pip3 安装的模块

[英]Python3 does not find modules installed by pip3

I'm having problems with python3.我在使用 python3 时遇到问题。 For some reason that I cannot figure out, the modules available in python3 are not the same as the ones installed via pip3.出于某种我无法弄清楚的原因,python3 中可用的模块与通过 pip3 安装的模块不同。

Running pip3 list in a Terminal returns:在终端中运行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)

Running this script to see what modules python3 has available returns:运行此脚本以查看python3有哪些模块可用返回:

 ['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.例如, nltk有一个旧版本。 pandas is missing. pandas不见了。

I've installed python via homebrew and I'm running scripts via Textmate2.我已经通过自制软件安装了 python,我正在通过 Textmate2 运行脚本。 However, I have the same problem when I run code in terminal, via python3 .但是,当我通过python3在终端中运行代码时,我遇到了同样的问题。 Both pip3 and python3 are installed in /usr/local/bin/ : pip3 和 python3 都安装在/usr/local/bin/

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

And that's also the version python3 is using:这也是 python3 正在使用的版本:

>>> 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.查看pip3脚本的第一行。

The first line (starting with #! should point to the same executable as the symbolic link for python 3:第一行(以#!开头的应该指向与 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.如果不是这种情况,请卸载pip并使用正确的 Python 版本重新安装。

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:如果你真的想确保你使用的是正确的 Python 和pip ,那么将它作为一个模块调用,如下所示:

python3.7 -m pip list

If you get the error No module named pip , then pip is not installed for this version of python.如果您收到错误No module named pip ,则该版本的 python 未安装pip

I ran to this problem in Windows.我在 Windows 中遇到了这个问题。 first of all I uninstall the package using cmd command pip3 uninstall moduleName .首先,我使用 cmd 命令pip3 uninstall moduleName卸载包。 Then based on python documentation I run command python -m pip install moduleName and my problem solved!然后基于 python 文档我运行命令python -m pip install moduleName并且我的问题解决了!

Here is the documentation: Installing Python Modules这是文档:安装 Python 模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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