Ongoing woes with the python (2.7.3) installation on my Ubuntu 12.04 machine and importing modules.
在我的Ubuntu 12.04机器上安装python(2.7.3)并导入模块时遇到了困难。
Here I am having an issue where I have definitely installed mechanize both on my machine and in various virtual environments.
在这里,我遇到了一个问题,我在机器和各种虚拟环境中都确实安装了机械。
I have tried installing from pip, easy_install and via python setup.py install
from this repo: https://github.com/abielr/mechanize.
我尝试从pip,easy_install和通过python setup.py安装从这个repo安装:https://github.com/abielr/mechanize。
All of this to no avail, as each time I enter my python interactive I get:
所有这一切都无济于事,因为每次我进入我的python互动时,我得到:
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
>>>
Other computers I install this on do not have a problem (a Mac, or a Windows machine at work, for instance, it's all good, installs and imports like normal).
我安装它的其他计算机没有问题(例如Mac,或工作中的Windows机器,它一切都很好,安装和导入正常)。
It's pretty much driving me crazy at this point, and I just want to get some work done.
在这一点上,这几乎让我发疯,我只是想完成一些工作。
UPDATE INFO (in response to comments):
更新信息(回应评论):
Out put of easy_install mechanize
and paths:
输出easy_install机械化和路径:
<me>@<host>:~$ sudo easy_install mechanize
[sudo] password for <me>:
Processing mechanize
Writing /home/<me>/mechanize/setup.cfg
Running setup.py -q bdist_egg --dist-dir /home/<me>/mechanize/egg-dist-tmp-zXwJ_d
warning: no files found matching '*.html' under directory 'docs'
warning: no files found matching '*.css' under directory 'docs'
warning: no files found matching '*.js' under directory 'docs'
mechanize 0.2.6.dev-20130112 is already the active version in easy-install.pth
Installed /usr/local/lib/python2.7/dist-packages/mechanize-0.2.6.dev_20130112-py2.7.egg
Processing dependencies for mechanize==0.2.6.dev-20130112
Finished processing dependencies for mechanize==0.2.6.dev-20130112
<me>@<host>:~$ ^C
<me>@<host>:~$ which pip
/home/<me>/bin/pip
<me>@<host>:~$ which python
/home/<me>/bin/python
<me>@<host>:~$ which easy_install
/home/<me>/bin/easy_install
<me>@<host>:~$
SECOND UPDATE: Seems to be something with mechanize, as if I add any other random package via pip, there is no problem (in this instance html5lib
)
第二个更新:似乎是机械化的东西,好像我通过pip添加任何其他随机包,没有问题(在这个例子中html5lib)
THIRD UPDATE (@DSM)
第三次更新(@DSM)
1)
>>> sys.path
['', '/home/<me>/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/home/<me>/local/lib/python2.7/site-packages/virtualenvwrapper-2.11-py2.7.egg', '/home/<me>/src/geopy', '/home/<me>/local/lib/python2.7/site-packages/BeautifulSoup-3.2.0-py2.7.egg', '/home/<me>/local/lib/python2.7/site-packages/django_sorting-0.1-py2.7.egg' ... <so on and so forth but mechanize is not here>]
>>>
2) *pretty long output of which most looks like:*
<me>@<host>:~$ ls -laR /usr/local/lib/python2.7/dist-packages/mech*
/usr/local/lib/python2.7/dist-packages/mechanize:
total 1144
...lots of other files, pretty much same permissions...
-rw-r--r-- 1 root staff 24916 Jan 11 01:19 _mechanize.py
...lots of other files...
3)
>>> import imp
>>> imp.find_module("mechanize")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
>>>
FOURTH EDIT (this is getting ridiculous :/): This is similar to a problem I've had before (Complete removal and fresh install of python on Ubuntu 12.04), where if I run everything with sudo, it's fine, but I don't know if I should have to do that... what's up with the permissions?
第四次编辑(这太荒谬了:/):这类似于我之前遇到的一个问题(在Ubuntu 12.04上完全删除并重新安装python),如果我用sudo运行一切,那很好,但我不知道知道我是否应该这样做......权限是什么?
14 个解决方案
#1
57
in my case it is permission problem. The package was somehow installed with root rw permission only, other user just cannot rw to it!
在我的情况下,这是许可问题。该软件包以某种方式安装了root rw权限,其他用户只是无法使用它!
#2
32
I had the same problem: script with import colorama
was throwing and ImportError, but sudo pip install colorama
was telling me "package already installed".
我有同样的问题:导入colorama的脚本抛出和ImportError,但是sudo pip install colorama告诉我“已经安装了包”。
My fix: run pip without sudo: pip install colorama
. Then pip agreed it needed to be installed, installed it, and my script ran.
我的修复:运行pip没有sudo:pip install colorama。然后pip同意它需要安装,安装它,我的脚本运行。
My environment is Ubuntu 14.04 32-bit; I think I saw this before and after I activated my virtualenv.
我的环境是Ubuntu 14.04 32位;我想我在激活我的virtualenv之前和之后都看到了这个。
UPDATE: even better, use python -m pip install <package>
. The benefit of this is, since you are executing the specific version of python that you want the package in, pip will unequivocally install the package in to the "right" python. Again, don't use sudo in this case... then you get the package in the right place, but possibly with (unwanted) root permissions.
更新:更好的是,使用python -m pip install
#3
11
It's the python path problem.
这是python路径问题。
In my case, I have python installed in:
在我的情况下,我安装了python:
/Library/Frameworks/Python.framework/Versions/2.6/bin/python,
/Library/Frameworks/Python.framework/Versions/2.6/bin/python,
and there is no site-packages directory within the python2.6.
并且python2.6中没有site-packages目录。
The package(SOAPpy) I installed by pip is located
我找到了由pip安装的软件包(SOAPpy)
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
And site-package is not in the python path, all I did is add site-packages to PYTHONPATH permanently.
并且site-package不在python路径中,我所做的就是永久地将站点包添加到PYTHONPATH。
- Open up Terminal
- 打开终端
- Type open .bash_profile
- 输入open .bash_profile
-
In the text file that pops up, add this line at the end:
在弹出的文本文件中,在末尾添加以下行:
export PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
export PYTHONPATH = $ PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
- Save the file, restart the Terminal, and you're done
- 保存文件,重新启动终端,然后就完成了
#4
5
The Python import mechanism works, really, so, either:
Python导入机制非常有用,所以:
- Your PYTHONPATH is wrong,
- 你的PYTHONPATH错了,
- Your library is not installed where you think it is
- 您的库未安装在您认为的位置
- You have another library with the same name masking this one
- 你有另一个同名的图书馆掩盖了这个
#5
3
I have been banging my head against my monitor on this until a young-hip intern told me the secret is to "python setup.py install" inside the module directory.
我一直在敲打我的显示器直到一个年轻的实习生告诉我秘密是在模块目录中“python setup.py install”。
For some reason, running the setup from there makes it just work.
出于某种原因,从那里运行安装程序使它正常工作。
To be clear, if your module's name is "foo":
要清楚,如果您的模块名称是“foo”:
[burnc7 (2016-06-21 15:28:49) git]# ls -l
total 1
drwxr-xr-x 7 root root 118 Jun 21 15:22 foo
[burnc7 (2016-06-21 15:28:51) git]# cd foo
[burnc7 (2016-06-21 15:28:53) foo]# ls -l
total 2
drwxr-xr-x 2 root root 93 Jun 21 15:23 foo
-rw-r--r-- 1 root root 416 May 31 12:26 setup.py
[burnc7 (2016-06-21 15:28:54) foo]# python setup.py install
<--snip-->
If you try to run setup.py from any other directory by calling out its path, you end up with a borked install.
如果您尝试通过调用其路径从任何其他目录运行setup.py,则最终会进行borked安装。
DOES NOT WORK:
不工作:
python /root/foo/setup.py install
DOES WORK:
工作:
cd /root/foo
python setup.py install
#6
2
In my case I had run pip install Django==1.11
and it would not import from the python
interpreter.
在我的情况下,我运行pip安装Django == 1.11,它不会从python解释器导入。
Browsing through pip's commands I found pip show
which looked like this:
通过pip的命令浏览我发现pip show看起来像这样:
> pip show Django
Name: Django
Version: 1.11
...
Location: /usr/lib/python3.4/site-packages
...
Notice the location says '3.4'. I found that the python
-command was linked to python2.7
注意位置显示'3.4'。我发现python-command链接到python2.7
/usr/bin> ls -l python
lrwxrwxrwx 1 root root 9 Mar 14 15:48 python -> python2.7
Right next to that I found a link called python3
so I used that. You could also change the link to python3.4
. That would fix it, too.
就在旁边,我发现了一个名为python3的链接,所以我使用了它。您还可以将链接更改为python3.4。那也可以解决它。
#7
1
I couldn't get my PYTHONPATH to work properly. I realized adding export
fixed the issue:
我无法让我的PYTHONPATH正常工作。我意识到添加导出修复了这个问题:
(did work)
(干了)
export PYTHONPATH=$PYTHONPATH:~/test/site-packages
vs.
与
(did not work)
(不工作)
PYTHONPATH=$PYTHONPATH:~/test/site-packages
#8
0
I had this exact problem, but none of the answers above worked. It drove me crazy until I noticed that sys.path was different after I had imported from the parent project. It turned out that I had used importlib to write a little function in order to import a file not in the project hierarchy. Bad idea: I forgot that I had done this. Even worse, the import process mucked with the sys.path--and left it that way. Very bad idea.
我有这个确切的问题,但上面的答案都没有奏效。它让我疯狂,直到我注意到从父项目导入后sys.path不同。事实证明,我曾使用importlib编写一个小函数,以便导入不在项目层次结构中的文件。不好的主意:我忘记了我做过这件事。更糟糕的是,导入过程与sys.path混乱 - 并保持这种方式。非常糟糕的主意。
The solution was to stop that, and simply put the file I needed to import into the project. Another approach would have been to put the file into its own project, as it needs to be rebuilt from time to time, and the rebuild may or may not coincide with the rebuild of the main project.
解决方案是停止它,只需将我需要导入的文件放入项目中。另一种方法是将文件放入自己的项目中,因为它需要不时地重建,并且重建可能与主项目的重建一致,也可能不一致。
#9
0
I had this problem with 2.7 and 3.5 installed on my system trying to test a telegram bot with Python-Telegram-Bot.
我在我的系统上安装了2.7和3.5这个问题,试图用Python-Telegram-Bot测试一个电报机器人。
I couldn't get it to work after installing with pip and pip3, with sudo or without. I always got:
使用pip和pip3安装后,无论是sudo还是不安装,我都无法使用它。我总是得到:
Traceback (most recent call last):
File "telegram.py", line 2, in <module>
from telegram.ext import Updater
File "$USER/telegram.py", line 2, in <module>
from telegram.ext import Updater
ImportError: No module named 'telegram.ext'; 'telegram' is not a package
Reading the error message correctly tells me that python is looking in the current directory for a telegram.py
. And right, I had a script lying there called telegram.py and this was loaded by python when I called import
.
正确读取错误消息告诉我python正在当前目录中查找telegram.py。是的,我在那里有一个名为telegram.py的脚本,当我调用import时,这是由python加载的。
Conclusion, make sure you don't have any package.py
in your current working dir when trying to import. (And read error message thoroughly).
结论,确保在尝试导入时当前工作目录中没有任何package.py。 (并彻底阅读错误消息)。
#10
0
python -m pip install
- helped me to solve this issue. I started facing this issue post upgrading the python to 2.7.14
(from 12
)
python -m pip install - 帮我解决了这个问题。将python升级到2.7.14(从12开始)后我开始面对这个问题
#11
0
I was able to correct this issue with a combined approach. First, I followed Chris' advice, opened a command line and typed 'pip show packagename' This provided the location of the installed package.
我能够通过组合方法纠正这个问题。首先,我按照Chris的建议,打开命令行并输入'pip show packagename'这提供了已安装软件包的位置。
Next, I opened python and typed 'import sys', then 'sys.path' to show where my python searches for any packages I import. Alas, the location shown in the first step was NOT in the list.
接下来,我打开python并输入'import sys',然后输入'sys.path'来显示我的python搜索我导入的任何包的位置。唉,第一步显示的位置不在列表中。
Final step, I typed 'sys.path.append('package_location_seen_in_step_1'). You optionally can repeat step two to see the location is now in the list.
最后一步,我输入'sys.path.append('package_location_seen_in_step_1')。您可以选择重复第二步,以查看该位置现在是否在列表中。
Test step, try to import the package again... it works.
测试步骤,尝试再次导入包...它的工作原理。
The downside? It is temporary, and you need to add it to the list each time.
不足之处?这是暂时的,您需要每次都将其添加到列表中。
#12
0
I had similar problem (on Windows) and the root cause in my case was ANTIVIRUS software! It has "Auto-Containment" feature, that wraps running process with some kind of a virtual machine. Symptoms are: pip install somemodule
works fine in one cmd-line window and import somemodule
fails when executed from another process with the error
我有类似的问题(在Windows上),我的案例的根本原因是ANTIVIRUS软件!它具有“Auto-Containment”功能,可以使用某种虚拟机包装运行进程。症状是:pip install somemodule在一个cmd-line窗口中工作正常,导入somemodule从另一个进程执行时出错
ModuleNotFoundError: No module named 'somemodule'
I hope it will save some time to somebody :)
我希望它能节省一些时间给某人:)
#13
-2
When you install via easy_install
or pip
, is it completing successfully? What is the full output? Which python installation are you using? You may need to use sudo
before your installation command, if you are installing modules to a system directory (if you are using the system python installation, perhaps). There's not a lot of useful information in your question to go off of, but some tools that will probably help include:
当您通过easy_install或pip安装时,它是否成功完成?什么是完整输出?你使用哪个python安装?如果要将模块安装到系统目录(如果使用的是系统python安装),则可能需要在安装命令之前使用sudo。你的问题中没有很多有用的信息可供使用,但一些可能有用的工具包括:
-
echo $PYTHONPATH
and/orecho $PATH
: when importing modules, Python searches one of these environment variables (lists of directories,:
delimited) for the module you want. Importing problems are often due to the right directory being absent from these listsecho $ PYTHONPATH和/或echo $ PATH:在导入模块时,Python会搜索所需模块的其中一个环境变量(目录列表,:分隔)。导入问题通常是由于这些列表中没有正确的目录
-
which python
,which pip
, orwhich easy_install
: these will tell you the location of each executable. It may help to know.哪个python,哪个pip,或者easy_install:这些将告诉你每个可执行文件的位置。知道可能会有所帮助。
-
Use virtualenv, like @JesseBriggs suggests. It works very well with
pip
to help you isolate and manage the modules and environment for separate Python projects.使用virtualenv,就像@JesseBriggs建议的那样。它与pip一起工作得很好,可以帮助您隔离和管理单独的Python项目的模块和环境。
#14
-5
If you learn how to use virtualenv (which is pretty dead-simple), you will have less of these issues. You'll just source the virtualenv and then you will be using local (to the project) packages.
如果你学习如何使用virtualenv(这很简单),你将会遇到更少的问题。您将只使用virtualenv,然后您将使用本地(到项目)包。
It solves a lot of headache for me with paths, versions, etc.
它通过路径,版本等解决了我很多头痛的问题。
#1
57
in my case it is permission problem. The package was somehow installed with root rw permission only, other user just cannot rw to it!
在我的情况下,这是许可问题。该软件包以某种方式安装了root rw权限,其他用户只是无法使用它!
#2
32
I had the same problem: script with import colorama
was throwing and ImportError, but sudo pip install colorama
was telling me "package already installed".
我有同样的问题:导入colorama的脚本抛出和ImportError,但是sudo pip install colorama告诉我“已经安装了包”。
My fix: run pip without sudo: pip install colorama
. Then pip agreed it needed to be installed, installed it, and my script ran.
我的修复:运行pip没有sudo:pip install colorama。然后pip同意它需要安装,安装它,我的脚本运行。
My environment is Ubuntu 14.04 32-bit; I think I saw this before and after I activated my virtualenv.
我的环境是Ubuntu 14.04 32位;我想我在激活我的virtualenv之前和之后都看到了这个。
UPDATE: even better, use python -m pip install <package>
. The benefit of this is, since you are executing the specific version of python that you want the package in, pip will unequivocally install the package in to the "right" python. Again, don't use sudo in this case... then you get the package in the right place, but possibly with (unwanted) root permissions.
更新:更好的是,使用python -m pip install
#3
11
It's the python path problem.
这是python路径问题。
In my case, I have python installed in:
在我的情况下,我安装了python:
/Library/Frameworks/Python.framework/Versions/2.6/bin/python,
/Library/Frameworks/Python.framework/Versions/2.6/bin/python,
and there is no site-packages directory within the python2.6.
并且python2.6中没有site-packages目录。
The package(SOAPpy) I installed by pip is located
我找到了由pip安装的软件包(SOAPpy)
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
And site-package is not in the python path, all I did is add site-packages to PYTHONPATH permanently.
并且site-package不在python路径中,我所做的就是永久地将站点包添加到PYTHONPATH。
- Open up Terminal
- 打开终端
- Type open .bash_profile
- 输入open .bash_profile
-
In the text file that pops up, add this line at the end:
在弹出的文本文件中,在末尾添加以下行:
export PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
export PYTHONPATH = $ PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
- Save the file, restart the Terminal, and you're done
- 保存文件,重新启动终端,然后就完成了
#4
5
The Python import mechanism works, really, so, either:
Python导入机制非常有用,所以:
- Your PYTHONPATH is wrong,
- 你的PYTHONPATH错了,
- Your library is not installed where you think it is
- 您的库未安装在您认为的位置
- You have another library with the same name masking this one
- 你有另一个同名的图书馆掩盖了这个
#5
3
I have been banging my head against my monitor on this until a young-hip intern told me the secret is to "python setup.py install" inside the module directory.
我一直在敲打我的显示器直到一个年轻的实习生告诉我秘密是在模块目录中“python setup.py install”。
For some reason, running the setup from there makes it just work.
出于某种原因,从那里运行安装程序使它正常工作。
To be clear, if your module's name is "foo":
要清楚,如果您的模块名称是“foo”:
[burnc7 (2016-06-21 15:28:49) git]# ls -l
total 1
drwxr-xr-x 7 root root 118 Jun 21 15:22 foo
[burnc7 (2016-06-21 15:28:51) git]# cd foo
[burnc7 (2016-06-21 15:28:53) foo]# ls -l
total 2
drwxr-xr-x 2 root root 93 Jun 21 15:23 foo
-rw-r--r-- 1 root root 416 May 31 12:26 setup.py
[burnc7 (2016-06-21 15:28:54) foo]# python setup.py install
<--snip-->
If you try to run setup.py from any other directory by calling out its path, you end up with a borked install.
如果您尝试通过调用其路径从任何其他目录运行setup.py,则最终会进行borked安装。
DOES NOT WORK:
不工作:
python /root/foo/setup.py install
DOES WORK:
工作:
cd /root/foo
python setup.py install
#6
2
In my case I had run pip install Django==1.11
and it would not import from the python
interpreter.
在我的情况下,我运行pip安装Django == 1.11,它不会从python解释器导入。
Browsing through pip's commands I found pip show
which looked like this:
通过pip的命令浏览我发现pip show看起来像这样:
> pip show Django
Name: Django
Version: 1.11
...
Location: /usr/lib/python3.4/site-packages
...
Notice the location says '3.4'. I found that the python
-command was linked to python2.7
注意位置显示'3.4'。我发现python-command链接到python2.7
/usr/bin> ls -l python
lrwxrwxrwx 1 root root 9 Mar 14 15:48 python -> python2.7
Right next to that I found a link called python3
so I used that. You could also change the link to python3.4
. That would fix it, too.
就在旁边,我发现了一个名为python3的链接,所以我使用了它。您还可以将链接更改为python3.4。那也可以解决它。
#7
1
I couldn't get my PYTHONPATH to work properly. I realized adding export
fixed the issue:
我无法让我的PYTHONPATH正常工作。我意识到添加导出修复了这个问题:
(did work)
(干了)
export PYTHONPATH=$PYTHONPATH:~/test/site-packages
vs.
与
(did not work)
(不工作)
PYTHONPATH=$PYTHONPATH:~/test/site-packages
#8
0
I had this exact problem, but none of the answers above worked. It drove me crazy until I noticed that sys.path was different after I had imported from the parent project. It turned out that I had used importlib to write a little function in order to import a file not in the project hierarchy. Bad idea: I forgot that I had done this. Even worse, the import process mucked with the sys.path--and left it that way. Very bad idea.
我有这个确切的问题,但上面的答案都没有奏效。它让我疯狂,直到我注意到从父项目导入后sys.path不同。事实证明,我曾使用importlib编写一个小函数,以便导入不在项目层次结构中的文件。不好的主意:我忘记了我做过这件事。更糟糕的是,导入过程与sys.path混乱 - 并保持这种方式。非常糟糕的主意。
The solution was to stop that, and simply put the file I needed to import into the project. Another approach would have been to put the file into its own project, as it needs to be rebuilt from time to time, and the rebuild may or may not coincide with the rebuild of the main project.
解决方案是停止它,只需将我需要导入的文件放入项目中。另一种方法是将文件放入自己的项目中,因为它需要不时地重建,并且重建可能与主项目的重建一致,也可能不一致。
#9
0
I had this problem with 2.7 and 3.5 installed on my system trying to test a telegram bot with Python-Telegram-Bot.
我在我的系统上安装了2.7和3.5这个问题,试图用Python-Telegram-Bot测试一个电报机器人。
I couldn't get it to work after installing with pip and pip3, with sudo or without. I always got:
使用pip和pip3安装后,无论是sudo还是不安装,我都无法使用它。我总是得到:
Traceback (most recent call last):
File "telegram.py", line 2, in <module>
from telegram.ext import Updater
File "$USER/telegram.py", line 2, in <module>
from telegram.ext import Updater
ImportError: No module named 'telegram.ext'; 'telegram' is not a package
Reading the error message correctly tells me that python is looking in the current directory for a telegram.py
. And right, I had a script lying there called telegram.py and this was loaded by python when I called import
.
正确读取错误消息告诉我python正在当前目录中查找telegram.py。是的,我在那里有一个名为telegram.py的脚本,当我调用import时,这是由python加载的。
Conclusion, make sure you don't have any package.py
in your current working dir when trying to import. (And read error message thoroughly).
结论,确保在尝试导入时当前工作目录中没有任何package.py。 (并彻底阅读错误消息)。
#10
0
python -m pip install
- helped me to solve this issue. I started facing this issue post upgrading the python to 2.7.14
(from 12
)
python -m pip install - 帮我解决了这个问题。将python升级到2.7.14(从12开始)后我开始面对这个问题
#11
0
I was able to correct this issue with a combined approach. First, I followed Chris' advice, opened a command line and typed 'pip show packagename' This provided the location of the installed package.
我能够通过组合方法纠正这个问题。首先,我按照Chris的建议,打开命令行并输入'pip show packagename'这提供了已安装软件包的位置。
Next, I opened python and typed 'import sys', then 'sys.path' to show where my python searches for any packages I import. Alas, the location shown in the first step was NOT in the list.
接下来,我打开python并输入'import sys',然后输入'sys.path'来显示我的python搜索我导入的任何包的位置。唉,第一步显示的位置不在列表中。
Final step, I typed 'sys.path.append('package_location_seen_in_step_1'). You optionally can repeat step two to see the location is now in the list.
最后一步,我输入'sys.path.append('package_location_seen_in_step_1')。您可以选择重复第二步,以查看该位置现在是否在列表中。
Test step, try to import the package again... it works.
测试步骤,尝试再次导入包...它的工作原理。
The downside? It is temporary, and you need to add it to the list each time.
不足之处?这是暂时的,您需要每次都将其添加到列表中。
#12
0
I had similar problem (on Windows) and the root cause in my case was ANTIVIRUS software! It has "Auto-Containment" feature, that wraps running process with some kind of a virtual machine. Symptoms are: pip install somemodule
works fine in one cmd-line window and import somemodule
fails when executed from another process with the error
我有类似的问题(在Windows上),我的案例的根本原因是ANTIVIRUS软件!它具有“Auto-Containment”功能,可以使用某种虚拟机包装运行进程。症状是:pip install somemodule在一个cmd-line窗口中工作正常,导入somemodule从另一个进程执行时出错
ModuleNotFoundError: No module named 'somemodule'
I hope it will save some time to somebody :)
我希望它能节省一些时间给某人:)
#13
-2
When you install via easy_install
or pip
, is it completing successfully? What is the full output? Which python installation are you using? You may need to use sudo
before your installation command, if you are installing modules to a system directory (if you are using the system python installation, perhaps). There's not a lot of useful information in your question to go off of, but some tools that will probably help include:
当您通过easy_install或pip安装时,它是否成功完成?什么是完整输出?你使用哪个python安装?如果要将模块安装到系统目录(如果使用的是系统python安装),则可能需要在安装命令之前使用sudo。你的问题中没有很多有用的信息可供使用,但一些可能有用的工具包括:
-
echo $PYTHONPATH
and/orecho $PATH
: when importing modules, Python searches one of these environment variables (lists of directories,:
delimited) for the module you want. Importing problems are often due to the right directory being absent from these listsecho $ PYTHONPATH和/或echo $ PATH:在导入模块时,Python会搜索所需模块的其中一个环境变量(目录列表,:分隔)。导入问题通常是由于这些列表中没有正确的目录
-
which python
,which pip
, orwhich easy_install
: these will tell you the location of each executable. It may help to know.哪个python,哪个pip,或者easy_install:这些将告诉你每个可执行文件的位置。知道可能会有所帮助。
-
Use virtualenv, like @JesseBriggs suggests. It works very well with
pip
to help you isolate and manage the modules and environment for separate Python projects.使用virtualenv,就像@JesseBriggs建议的那样。它与pip一起工作得很好,可以帮助您隔离和管理单独的Python项目的模块和环境。
#14
-5
If you learn how to use virtualenv (which is pretty dead-simple), you will have less of these issues. You'll just source the virtualenv and then you will be using local (to the project) packages.
如果你学习如何使用virtualenv(这很简单),你将会遇到更少的问题。您将只使用virtualenv,然后您将使用本地(到项目)包。
It solves a lot of headache for me with paths, versions, etc.
它通过路径,版本等解决了我很多头痛的问题。