Python 使用 pip 安装模块,未找到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40834656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:04:06  来源:igfitidea点击:

Installed module using pip, not found

pythonpython-3.xubuntupippythonpath

提问by RickSanchez725

I am trying to install a package called "simpleguitk" via pip. (On Ubuntu 16.04 with Python 3.5)
After running

我正在尝试通过 pip 安装一个名为“simpleguitk”的包。(在带有 Python 3.5 的 Ubuntu 16.04 上)
运行后

sudo -H pip3 install simpleguitk

it says installation is completed successfully. (Except for the pygame dependecy which is actually optional)

它说安装成功完成。(除了实际上是可选的 pygame 依赖项)

Collecting simpleguitk
Using cached SimpleGUITk-1.1.3.tar.gz
Collecting Pillow>=2.0.0 (from simpleguitk)
Using cached Pillow-3.4.2-cp35-cp35m-manylinux1_x86_64.whl
Collecting pygame>=1.9.0 (from simpleguitk)
Could not find a version that satisfies the requirement pygame>=1.9.0 (from simpleguitk) (from versions: 1.9.2.dev1, 1.9.2b7, 1.9.2b8)
No matching distribution found for pygame>=1.9.0 (from simpleguitk)

I cannot find the package at /usr/local/lib/python3.5/dist-packages or /usr/lib/python3.5 or /usr/lib/python3

我在 /usr/local/lib/python3.5/dist-packages 或 /usr/lib/python3.5 或 /usr/lib/python3 找不到包

When I try to import the module it says:

当我尝试导入模块时,它说:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'simpleguitk'

I tried to reinstall it, but running:

我试图重新安装它,但运行:

sudo -H pip3 uninstall simpleguitk

returns: "Cannot uninstall requirement simpleguitk, not installed "

返回:“无法卸载要求 simpleguitk,未安装”

I have tried this on both pip 8.1.2 and pip 9.0.1 with the same results. I have even reinstalled Ubuntu, but still the same.

我在 pip 8.1.2 和 pip 9.0.1 上都试过这个,结果相同。我什至重新安装了 Ubuntu,但还是一样。

I think Python Path is wrong as it does not have python 3.5 but I do not know how to fix it

我认为 Python Path 是错误的,因为它没有 python 3.5 但我不知道如何修复它

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0']

回答by cartographer

Make sure you're installing it for the version of python you're using, with

确保为您正在使用的 python 版本安装它,使用

/path/to/your/python -m pip install <package>

回答by RickSanchez725

pipneeds python, and sometimes the pythonyou are trying to execute your *.pymay not be same as the pythonbinary used by pip.

pip需求python,有时python您要执行你*.py可能不一样,python所使用的二进制pip

Can you retry installing following these steps:

您能否按照以下步骤重试安装:

which python

which python

Let's say it prints:

假设它打印:

/usr/bin/python

Means you can use:

意味着您可以使用:

/usr/bin/python -m pip install <package>

Or you can try to choose from the different versions you have of python.

或者您可以尝试从您拥有的不同版本的 python 中进行选择。

Now try executing you *.pyusing

现在尝试*.py使用

/usr/bin/python *.py

/usr/bin/python *.py

回答by Uma Senthil

The issue could be that the version of python you used to install the module does not match the version python you are trying to import from.

问题可能是您用于安装模块的 python 版本与您尝试从中导入的 python 版本不匹配。

  1. Find out whether the module in the python version you wanted you can try using the command: pip3 freezeto get the list of packages installed for version of python(In your case, it is python3.5).

  2. Before that, check different versions of python installed in your machine. You can use the command locate /python | grep /binif you have python2.7 and python3.5, then you should use the corresponding pip/pip3 to install the modules.

  3. Open the corresponding python shell (python3) and try to import again

  1. 找出您想要的python版本中的模块是否可以尝试使用命令:pip3 freeze获取为python版本安装的软件包列表(在您的情况下,它是python3.5)。

  2. 在此之前,请检查您机器中安装的不同版本的python。locate /python | grep /bin如果你有python2.7和python3.5可以使用该命令,那么你应该使用对应的pip/pip3来安装模块。

  3. 打开对应的python shell(python3),再次尝试导入

回答by Ibolit

I had a similar problem with PyCharm, where the dependencies I installed using pip would work for the editor windows (i.e., there were no error reports about imports), but the project would complain about the dependencies when I tried to run it. Turns out, I set up a virtual environment for that project afterI created the tasks that ran my project and tests. I had to go to the window where you set up the tasks and make sure that all of them used the correct venv. Hope this is useful.

我在 PyCharm 中遇到了类似的问题,我使用 pip 安装的依赖项适用于编辑器窗口(即,没有关于导入的错误报告),但是当我尝试运行该项目时,该项目会抱怨依赖项。事实证明,我创建了运行我的项目和测试的任务之后,我为该项目设置了一个虚拟环境。我必须转到您设置任务的窗口,并确保所有任务都使用正确的 venv。希望这是有用的。

回答by Sumukha Pk

The module may be installed but the program doesn't run. This happens because of 2 different versions of python co-existing. So run your Py Script with the location of the python version you have installed the module for, say usr/bin/python python.pyor /usr/bin/python3 python.py.

模块可能已安装,但程序未运行。这是因为 2 个不同版本的 python 共存。因此,使用您已为其安装模块的 Python 版本的位置运行您的 Py 脚本,例如usr/bin/python python.py/usr/bin/python3 python.py.

Hope this helps in your progress!

希望这有助于您的进步!