Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NumPy in Visual Studio

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?

like image 827
user1477388 Avatar asked Nov 24 '13 20:11

user1477388


People also ask

How do I add NumPy code to Visual Studio?

To install numpy, select pip from the dropdown for Python Environment, then type numpy and click on the “install numpy from PyPI” as shown below. Similarly search for scipy and install it using pip. If you get any errors in installing scipy, then download first anaconda from the following site.

Can you pip install NumPy?

NumPy can be installed with conda , with pip , with a package manager on macOS and Linux, or from source.


3 Answers

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

like image 147
Daniel Avatar answered Oct 13 '22 21:10

Daniel


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.
like image 34
Kyle Avatar answered Oct 13 '22 21:10

Kyle


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.
like image 44
Roland Smith Avatar answered Oct 13 '22 22:10

Roland Smith