Using NumPy in Visual Studio

2020-03-08 10:20发布

I downloaded http://pytools.codeplex.com/ (Python Tools for Visual Studio) so that I could write Python in Visual Studio.

The problem is when I try to use the most basic package "numpy" like so:

import numpy

It says "No module named 'numpy'."

How can I use NumPy and SciPy in Visual Studio?

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.

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:

...
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?

7条回答
叼着烟拽天下
2楼-- · 2020-03-08 10:53

In Visual Studio 2013 Community Edition with a Python 2.7 environment, the following worked for me:

Open the Python Environments menu in Solution Explorer, and click on "Install Python Package..."

Then write "numpy":

查看更多
倾城 Initia
3楼-- · 2020-03-08 10:57

I actually ran into the same set of problems when trying to use 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 Windows for details. Essentially you can either use the installer (if one is available) or use pip to do the installation.

查看更多
姐就是有狂的资本
4楼-- · 2020-03-08 10:57

From PTVS Installation:

2. Installing packages individually

Here are some recommended packages. Generally you want to install packages using pip or through the interface in Visual Studio (which uses pip), 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.

I installed numpy and scipy from these links, and it works perfectly with Visual Studio.

查看更多
手持菜刀,她持情操
5楼-- · 2020-03-08 11:04

Make sure C++ Common Tools are installed in Visual Studio:

Visual Studio 2015 Setup

查看更多
一纸荒年 Trace。
6楼-- · 2020-03-08 11:06

Two solutions worked for me:

  1. Going directly to my Python folder and installing the packages using pip.
  2. Creating a virtual environment in my project and installing packages from within Visual Studio.
查看更多
可以哭但决不认输i
7楼-- · 2020-03-08 11:08

Consider using a more feature-rich Windows distribution of Python, like Anaconda. It comes with a boatload of packages included into the installer. This is quite handy for those who are new to Python, especially when they are using Windows.

查看更多
登录 后发表回答