Python 在 Windows 中通过 Anaconda 安装 NumPy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26318995/
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
Installing NumPy via Anaconda in Windows
提问by Karnivaurus
I am trying to use Numpy in a Python 2.7.8 script in Windows. So, I download and installed the latest version of Anaconda (I also want to use some of the other tools in Anaconda) to the directory "C:/Anaconda". As default, I checked the boxing asking me if I wanted to add the path to the binary files to the Windows PATH.
我正在尝试在 Windows 的 Python 2.7.8 脚本中使用 Numpy。因此,我将最新版本的 Anaconda(我也想使用 Anaconda 中的其他一些工具)下载并安装到目录“C:/Anaconda”。默认情况下,我检查了框框,询问我是否要将二进制文件的路径添加到 Windows PATH。
After checking PATH, it contains the following: "C:\Anaconda;C:\Anaconda\Scripts".
检查 PATH 后,它包含以下内容:“C:\Anaconda;C:\Anaconda\Scripts”。
Then, after installation I open a new Command Prompt, and in the Python envirnoment, I enter "import numpy", but this gives the error: "ImportError: No module named numpy".
然后,安装后我打开一个新的命令提示符,在 Python 环境中,我输入“import numpy”,但这给出了错误:“ImportError: No module named numpy”。
What stage have I missed out in the installation process?
我在安装过程中错过了哪个阶段?
***** EDIT *****
***** 编辑 *****
I have just noticed that there is no file called "numpy" in either "C:\Anaconda" or "C:\Anaconda\Scripts". But according to the Anaconda website (http://docs.continuum.io/anaconda/pkg-docs.html), the installation should come with Numpy...
我刚刚注意到在“C:\Anaconda”或“C:\Anaconda\Scripts”中没有名为“numpy”的文件。但是根据 Anaconda 网站(http://docs.continuum.io/anaconda/pkg-docs.html),安装应该带有 Numpy ...
***** EDIT *****
***** 编辑 *****
It seems that Windows was running Python from an existing version of Python I had installed, which was not associated with NumPy. After deleting this, and running Python from the Anaconda installation, NumPy is now being recognised.
似乎 Windows 正在从我安装的 Python 的现有版本运行 Python,该版本与 NumPy 无关。删除它并从 Anaconda 安装运行 Python 后,现在可以识别 NumPy。
回答by spock
Anaconda folder basically resides in C:\Users\\Anaconda. Try setting the PATH to this folder.
Anaconda 文件夹基本上位于 C:\Users\\Anaconda 中。尝试将 PATH 设置为该文件夹。
回答by Adobe
Yep you should start anaconda's python in order to use python libs which come with anaconda. Or otherwise you have to manually add anaconda\libto pythonpathwhich is less trivial. You can start anaconda's python by a full path:
是的,您应该启动 anaconda 的 python 以使用 anaconda 附带的 python 库。否则,您必须手动添加anaconda\lib,pythonpath这不太重要。可以通过完整路径启动anaconda的python:
path\to\anaconda\python.exe
or you can run the following two commands as an admin in cmd to make windows pipe every .pyfile to anaconda's python:
或者您可以在 cmd 中以管理员身份运行以下两个命令,以使 windows 将每个.py文件通过管道传输到 anaconda 的 python:
assoc .py=Python.File
ftype Python.File=C:\path\to\Anaconda\python.exe "%1" %*
after this you'll be able just to call python scripts without specifying the python executable at all.
在此之后,您将能够只调用 python 脚本而无需指定 python 可执行文件。
回答by Daniel
I had the same problem, getting the message "ImportError: No module named numpy".
我遇到了同样的问题,收到消息“ImportError: No module named numpy”。
I'm also using anaconda and found out that I needed to add numpy to the ENV I was using. You can check the packages you have in your environment with the command:
我也在使用 anaconda 并发现我需要将 numpy 添加到我使用的 ENV 中。您可以使用以下命令检查环境中的软件包:
conda list
畅达清单
So, when I used that command, numpy was not displayed. If that is your case, you just have to add it, with the command:
因此,当我使用该命令时,没有显示 numpy。如果是这种情况,则只需使用以下命令添加它:
conda install numpy
康达安装numpy
After I did that, the error with the import numpywas gone
在我这样做之后,错误import numpy消失了
回答by Ishu Goyal
Move path\to\anacondain the PATH above path\to\python
path\to\anaconda在上面的 PATH 中移动path\to\python
回答by simpleParadox
The above answers seem to resolve the issue. If it doesn't, then you may also try to update conda using the following command.
上面的答案似乎解决了这个问题。如果没有,那么您也可以尝试使用以下命令更新 conda。
conda update conda
And then try to install numpy using
然后尝试使用安装 numpy
conda install numpy

