You are on page 1of 6

01/11/2017 Usando Visual Studio 2013 para Python (3.

4) com NumPy e SciPy no Windows | Blog de Thusitha Mabotuwana

Thusitha Mabotuwana's Blog

Using Visual Studio 2013 for Python (3.4) with NumPy and SciPy on Windows
Posted on July 6, 2015

3 Votes

There seem to be various editors for Python and there are many articles online (e.g., this blog post) that discuss
the features of the various editors. PyCharm by JetBrains seems pretty popular, but while I was Googling for
Python editors, I came across Python Tools for Visual Studio. Coming from a C# background, I thought Id give it
a shot before trying out a totally new editor (Ive moved onto Spyder now though).

The first thing you need to do is download PTVS from CodePlex. I downloaded PTVS 2.1 VS 2013.msi since Im on
VS2013. Of course youll need to install Python first if you havent done so already I installed 3.4 (64-bit initially
but had to revert to 32-bit later).

At this point you should be able to create a Python project in Visual Studio here is a good tutorial on how to
create your first Python program in VS. Basically you create a new Python project, very similar to how you would
create a .net application.

Creating a new project creates a new .py file with one line of code:

Now you hit F5, it runs your Python code:

https://thusithamabotuwana.wordpress.com/2015/07/06/using-visual-studio-2013-for-python-3-4-with-numpy-and-scipy-on-wind 1/6
01/11/2017 Usando Visual Studio 2013 para Python (3.4) com NumPy e SciPy no Windows | Blog de Thusitha Mabotuwana

This is the easy part. What I was having trouble was figuring out how to add external libraries and import these.
Following is the simple Python code I was trying to run (from the Udacity Machine Learning class):

import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)
print(clf.predict([[-0.8, -1]]))

This is when I started having trouble. VS kept complaining about No module named numpy. and kept
stopping at the import statement.

If you google visual studio no module named numpy or no module named numpy youll find tons of threads
with various suggestions, including installing/upgrading pip (pip comes with 3.4), using easy_install and running
other registry updates. I couldnt get any of these to work. With pip, it gave me false hope looking as if everything
was fine:

but then stopped out with errors (more on installing using command line later).

After lots of searching, I decided to try the numpy Windows installer available at
http://www.scipy.org/scipylib/download.html. Theres only 32-bit version available on this official site, so I just
tried installing that, but ended up with the following error saying python was not found in the registry:

https://thusithamabotuwana.wordpress.com/2015/07/06/using-visual-studio-2013-for-python-3-4-with-numpy-and-scipy-on-wind 2/6
01/11/2017 Usando Visual Studio 2013 para Python (3.4) com NumPy e SciPy no Windows | Blog de Thusitha Mabotuwana

Heres what finally worked

I uninstalled my 64-bit Python and reinstalled Python 32-bit.

Then tried installing numpy which worked!

Similarly, I could install other modules too. sklearn installed like a charm:

https://thusithamabotuwana.wordpress.com/2015/07/06/using-visual-studio-2013-for-python-3-4-with-numpy-and-scipy-on-wind 3/6
01/11/2017 Usando Visual Studio 2013 para Python (3.4) com NumPy e SciPy no Windows | Blog de Thusitha Mabotuwana

The previous code requires scipy, so I installed scipy too (from http://www.scipy.org/scipylib/download.html):

Now my Python code runs like a charm in Visual Studio!

https://thusithamabotuwana.wordpress.com/2015/07/06/using-visual-studio-2013-for-python-3-4-with-numpy-and-scipy-on-wind 4/6
01/11/2017 Usando Visual Studio 2013 para Python (3.4) com NumPy e SciPy no Windows | Blog de Thusitha Mabotuwana

So just to recap, these are the steps to follow:

1. Install Python 32-bit. Make sure Add python.exe to path is enabled.


2. Install Python Tools for Visual Studio.
3. Install numpy 32-bit and any other external modules you need.
4. Run you code!

Seems pretty straight-forward, but lots of people, including myself, seem to have trouble getting Visual Studio to
work with Python, especially getting the external modules to work.

By the way, there are unofficial versions of numpy available in 64-bit, and also Windows versions of Python
available (like IronPython), but I havent really played around with these. Im sure some of these combinations
would work equally well.

Lastly, it seems pretty straightforward to install Python modules using pip. Essentially there are (at least?) 3 ways

if theres a zip file (or a tar.gz), simply download and unzip into a folder (it should contain a file called setup.py)
see the YouTube video here. Then go to that folder in a command prompt and do:
python setup.py install

if you downloaded a .whl file, just open a command prompt and type:
pip install some-package.whl

install directly using pip (no need to change directory or anything, just open a command window):
pip install U packageName (e.g., PySide)

Voc precisar usar um dos dois mtodos acima para instalar pacotes que no possuem os instaladores do
Windows. Por exemplo, matplotlib tinha um instalador, mas tem dependncia de seis que no possui um
instalador. Matplotlib tambm requer data e pyparsing, e http://www.lfd.uci.edu/~gohlke/pythonlibs foi um
timo recurso para baixar esses mdulos.

https://thusithamabotuwana.wordpress.com/2015/07/06/using-visual-studio-2013-for-python-3-4-with-numpy-and-scipy-on-wind 5/6
01/11/2017 Usando Visual Studio 2013 para Python (3.4) com NumPy e SciPy no Windows | Blog de Thusitha Mabotuwana
Anncios

Gpu Geforce PLACA DE VIDEO Placa De Video


Galax Gtx1060 SAPPHIRE Evga Geforce

R$1.030,96 R$399,42 R$928,12


R$1.030,96 Compre!
Compre agora! Compre agora! Compre agora!

Like
Be the first to like this.

Relacionados

Grficos com WPF / C # Trabalhando com vrias instalaes de Importando o cdigo-fonte existente para o
Em "Geral" python no Windows Eclipse
Em "Geral" Em "Geral"

Esta entrada foi postada em Geral e marcou a instalao de .whl no Windows , Nenhum mdulo chamado numpy , python setup.py install , python no foi encontrado no
registro , scipy , Visual Studio para Python , numpy visual numpy . Marcar como marcador o permalink .

3 Respostas ao uso do Visual Studio 2013 para Python (3.4) com NumPy e SciPy no Windows

Pingback: lanando o Spyder no Windows | Blog de Thusitha Mabotuwana

Annimo diz:
27 de janeiro de 2016 s 7:24 da manh

timo homem do artigo. Me ajudou uma tonelada depois de passar horas tentando fazer o NumPy trabalhar com um script
em vez de uma janela de console. Posso dizer que isso funciona com o Visual Studio 2015 tambm.
Resposta

Annimo diz:
30 de janeiro de 2016 s 4:49 da manh

Muito obrigado!
Eu no precisava do instalador do Windows para numpy, por sinal.
apenas fazendo pip install - Um numpy na linha de comando j funcionou.
Resposta

Blog de Thusitha Mabotuwana


Blog no WordPress.com.

https://thusithamabotuwana.wordpress.com/2015/07/06/using-visual-studio-2013-for-python-3-4-with-numpy-and-scipy-on-wind 6/6

You might also like