[英]Python: modul not found after Anaconda installation
I've successfully installed Python 2.7 and Anaconda but when i try to import a library i get always this error:我已经成功安装了 Python 2.7 和 Anaconda,但是当我尝试导入库时,总是出现此错误:
>>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scipy
I've set up the PYTHONHOME
to C:\\Python27
and PYTHONPATH
to C:\\Python27\\Lib
.我已将PYTHONHOME
设置为C:\\Python27
并将PYTHONPATH
为C:\\Python27\\Lib
。
EDIT : content of PATH编辑:路径的内容
In my $PATH variable i have C:\\Users\\Mattia\\Anaconda2
, C:\\Users\\Mattia\\Anaconda2\\Scripts
and C:\\Users\\Mattia\\Anaconda2\\Library\\bin
.在我的 $PATH 变量中,我有C:\\Users\\Mattia\\Anaconda2
、 C:\\Users\\Mattia\\Anaconda2\\Scripts
和C:\\Users\\Mattia\\Anaconda2\\Library\\bin
。
Do i have to set any other env veriables?我是否必须设置任何其他环境变量?
The problem is that you should not have either PYTHONPATH
or PYTHONHOME
set.问题是您不应该设置PYTHONPATH
或PYTHONHOME
。 They are both pointing to a non-Continuum version of Anaconda, I believe.我相信,他们都指向 Anaconda 的非 Continuum 版本。 Anaconda will install (by default) into a directory called Anaconda
, either at C:\\Anaconda
or at C:\\Users\\USERNAME\\Anaconda
(IIRC). Anaconda 将(默认情况下)安装到名为Anaconda
的目录中,位于C:\\Anaconda
或C:\\Users\\USERNAME\\Anaconda
(IIRC)。 It is generally recommended that you should not ever set PYTHONPATH
or PYTHONHOME
, except as a last resort, exactly because of these kinds of problems.通常建议您永远不要设置PYTHONPATH
或PYTHONHOME
,除非作为最后的手段,正是因为这些问题。
You can see which Python interpreter you're running by doing:您可以通过执行以下操作来查看您正在运行的 Python 解释器:
>>> import sys
>>> sys.executable
And then you can see what directories are ending up in your Python library path (where import
statements will look for packages, such as scipy
and numpy
) by doing one of the following:然后,您可以通过执行以下操作之一来查看 Python 库路径中的最终目录( import
语句将在其中查找包,例如scipy
和numpy
):
>>> import sys
>>> sys.path
or the more readable version:或更易读的版本:
>>> import sys
>>> for p in sys.path:
... print p
As pointed out by @Mr.F the error was given by the presence of the PYTHONPATH
and PYTHONHOME
.正如@Mr.F 所指出的,错误是由PYTHONPATH
和PYTHONHOME
的存在引起的。 Deleting them i was able to use the Anaconda version of python.删除它们后,我就可以使用 Anaconda 版本的 python。
If you have module not found error, you may need to launch python from anaconda terminal using "python" instead of the shortened "py".如果您有模块未找到错误,您可能需要使用“python”而不是缩短的“py”从 anaconda 终端启动 python。 I had my module installed properly, but spent forever trying to fix it because of this.我已经正确安装了我的模块,但因此花了很长时间试图修复它。 Apparently py does not launch the anaconda activated or anaconda base environment, but launches another version of python.显然PY不启动激活了蟒蛇或蟒蛇基础环境,但推出蟒蛇的另一个版本。
尝试再次安装scipy
:
conda install numpy scipy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.