17

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?

Innat
  • 16,113
  • 6
  • 53
  • 101
user1477388
  • 20,790
  • 32
  • 144
  • 264
  • 2
    Did you install numpy? It's not "the most basic package" since it's not in the standard library. – Wooble Nov 24 '13 at 21:04
  • I was hoping there would be a way to install dependencies via python or through the IDE (Visual Studio, in this case). Must I do it myself, manually? Disclaimer: I'm very new to python development :) – user1477388 Nov 24 '13 at 21:05
  • 1
    http://stackoverflow.com/a/10558328/1265154; or, better, with binary installer http://www.lfd.uci.edu/~gohlke/pythonlibs/ – alko Nov 24 '13 at 21:31
  • Thanks, but this is getting silly! I was expecting "install python package" to actually work... It appears there is a compiler error or something as per https://github.com/SheffieldML/GPy/issues/63 I think I am just going to use Canopy Express. I remember it was pretty awesome for Python. – user1477388 Nov 24 '13 at 21:36

7 Answers7

35

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":

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daniel
  • 1,319
  • 14
  • 19
5

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.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kyle
  • 51
  • 1
  • 2
3

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.

Edit:

As of 2020, I would suggest using the python.org distribution of Python. Compiler issues on ms-windows have finally been fixed, so a lot of projects now provide binary packages (wheels) for ms-windows. Among others numpy, pandas, matplotlib, pillow, Cython and PyNaCl.

Note that wheel names ending in:

  • win_amd64.whl are for 64-bit versions of ms-windows, and
  • win32.whl are for 32-bit.
Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • Thanks Anaconda looks pretty cool. I am going to use Canopy Express https://www.enthought.com/products/epd/free/ which is also very cool (and free)! Someday maybe Microsoft will get their act together with this :) – user1477388 Nov 24 '13 at 21:44
  • 5
    @user1477388 Anaconda is also free. It's the add-ons (like optimized math and database libraries) that cost money. Either Anaconda or Canopy Express would be fine. I can sympathize with your plight. I'm used to working with FreeBSD and Linux which come with a host of free tools either installed or easily available. Every time I have to use a Windows box it feels like a barren wasteland in comparison. – Roland Smith Nov 24 '13 at 21:56
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Thusi
  • 929
  • 7
  • 5
2

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

Visual Studio 2015 Setup

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bohdan
  • 1,987
  • 16
  • 23
1

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.

Community
  • 1
  • 1
Charles Clayton
  • 17,005
  • 11
  • 87
  • 120
1

See under Extra in the Visual Studio (Extra-Python-Interactive Window).

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
omedahunsi
  • 11
  • 1