Python 在 Visual Studio 中使用 NumPy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20180926/
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
Using NumPy in Visual Studio
提问by user1477388
I downloaded http://pytools.codeplex.com/(Python Tools for Visual Studio) so that I could write Python in Visual Studio.
我下载了http://pytools.codeplex.com/(VisualStudio 的 Python 工具),以便我可以在 Visual Studio 中编写 Python。
The problem is when I try to use the most basic package "numpy" like so:
问题是当我尝试使用最基本的包“numpy”时,如下所示:
import numpy
It says "No module named 'numpy'."
它说“没有名为 'numpy' 的模块。”
How can I use NumPy and SciPy in Visual Studio?
如何在 Visual Studio 中使用 NumPy 和 SciPy?
Note: I am using Canopy Express on another machine which works perfectly; however, I don't want to install it on this machine since I already have Visual Studio installed.
注意:我在另一台完美运行的机器上使用Canopy Express;但是,我不想在这台机器上安装它,因为我已经安装了 Visual Studio。
I added the Python 3.3 environment to my Python "solution" by right-clicking Python environments and clicking add an environment. But, after right-clicking my environment and clicking install Python package, I typed in "numpy" and got this error when trying to install it:
我通过右键单击 Python 环境并单击添加环境将 Python 3.3 环境添加到我的 Python“解决方案”中。但是,在右键单击我的环境并单击安装 Python 包后,我输入了“numpy”并在尝试安装它时出现此错误:
...
creating build
creating build\src.win32-3.3
creating build\src.win32-3.3\numpy
creating build\src.win32-3.3\numpy\distutils
building library "npymath" sources
No module named 'numpy.distutils.msvccompiler' in numpy.distutils; trying from distutils
error: Unable to find vcvarsall.bat
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in c:\users\dom\appdata\local\temp\pip_build_Dom\numpy
Storing complete log in C:\Users\Dom\pip\pip.log
'numpy' failed to install. Exit code: 1
How can I install NumPy?
如何安装 NumPy?
采纳答案by Roland Smith
Consider using a more feature-rich Windows distribution of Python, like Anaconda. It comes with a boatload of packagesincluded into the installer. This is quite handy for those who are new to Python, especially when they are using Windows.
考虑使用功能更丰富的 Python 的 Windows 发行版,例如Anaconda。它附带了安装程序中包含的大量软件包。这对于刚接触 Python 的人来说非常方便,尤其是当他们使用 Windows 时。
Edit:
编辑:
As of 2020, I would suggest using the python.orgdistribution of Python.Compiler issues on ms-windows have finallybeen fixed, so a lot of projects now provide binary packages (wheels) for ms-windows. Among others numpy, pandas, matplotlib, pillow, Cythonand PyNaCl.
到 2020 年,我建议使用python.orgPython的发行版。ms-windows 上的编译器问题终于得到修复,所以现在很多项目都提供了 ms-windows 的二进制包(轮子)。除其他外numpy,pandas,matplotlib,pillow,Cython和PyNaCl。
Note that wheel names ending in:
请注意,车轮名称以以下结尾:
win_amd64.whlare for 64-bit versions of ms-windows, andwin32.whlare for 32-bit.
win_amd64.whl适用于 64 位版本的 ms-windows,以及win32.whl用于 32 位。
回答by Kyle
Two solutions worked for me:
两种解决方案对我有用:
- Going directly to my Python folder and installing the packages using pip.
- Creating a virtual environment in my project and installing packages from within Visual Studio.
- 直接进入我的 Python 文件夹并使用 pip 安装包。
- 在我的项目中创建一个虚拟环境并从 Visual Studio 中安装包。
回答by Thusi
I actually ran into the same set of problems when trying to use Visual Studio for Python.
在尝试使用 Visual Studio for Python 时,我实际上遇到了同样的问题。
I managed to get things to work at the end - please see Using Visual Studio 2013 for Python (3.4) with NumPy and SciPy on Windowsfor details. Essentially you can either use the installer (if one is available) or use pipto do the installation.
我设法让事情在最后工作 - 请参阅在 Windows 上使用 Visual Studio 2013 for Python (3.4) 和 NumPy 和 SciPy了解详细信息。基本上,您可以使用安装程序(如果有)或使用pip进行安装。
回答by Bohdan
回答by Daniel
In Visual Studio 2013 Community Edition with a Python 2.7 environment, the following worked for me:
在具有 Python 2.7 环境的 Visual Studio 2013 Community Edition 中,以下对我有用:
Open the Python Environments menu in Solution Explorer, and click on "Install Python Package..."
在解决方案资源管理器中打开 Python 环境菜单,然后单击“安装 Python 包...”
Then write "numpy":
然后写“ numpy”:
回答by Charles Clayton
From PTVS Installation:
从PTVS 安装:
2. Installing packages individually
Here are some recommended packages. Generally you want to install packages using
pipor through the interface in Visual Studio (which usespip), as this will ensure that you get the latest version that will work with your version of Python, as well as any dependencies.Some packages have complex dependencies and need to be downloaded manually, either from the project's website or from Christoph Gohlke's package collection.
2. 单独安装包
这里有一些推荐的包。通常,您希望使用
pip或通过 Visual Studio 中的界面(使用pip)安装包,因为这将确保您获得适用于您的 Python 版本以及任何依赖项的最新版本。有些包具有复杂的依赖关系,需要从项目网站或Christoph Gohlke 的包集合中手动下载。
I installed numpyand scipyfrom these links, and it works perfectly with Visual Studio.
我从这些链接安装numpy并安装了scipy它,它与 Visual Studio 完美配合。
回答by omedahunsi
See under Extra in the Visual Studio (Extra-Python-Interactive Window).
请参阅 Visual Studio 中的 Extra 下(Extra-Python-Interactive 窗口)。
It has the ability to switch the interactive console through a different platform/Python version (32-bit, 64-bit, Debug, and Anaconda (which has the NumPy package)).
它能够通过不同的平台/Python 版本(32 位、64 位、Debug 和 Anaconda(具有 NumPy 包))切换交互式控制台。


