Recently I acquired a Microsoft Surface Pro 3 and of course I installed Python.
It turned out that installing Python on Windows has its own caveats – similar to the particularities of Python on OS X.
I wanted to have a little more control and decided to install the packages myself, starting with Python from http://python.org/.
There are two important questions:
- Python 2 or Python 3?
- 32bit or 64bit?
I decided to install the 32bit version of Python 2.7 for compatibility reasons.
You can install Python 3.4 in parallel. It will install into its own directory and it will have its own uninstall entry in the system panel.
Like on Mac OS X I installed virtualenv to manage multiple Environments with different sets of installed packages.
A good Windows specific how-to can be found on Tyler Butler’s page.
He also explains how to integrate with PowerShell via the virtualenvwrapper-powershell package.
If you are using PowerShell for the first time he also Points out how to enable the execution of scripts (see this TechNet article in general and this help page on Microsoft TechNet in particular). You have to explicitly Permit the execution of unsigned scripts. You can list your machine’s policies with this command in PowerShell:
My policies look like this:
RemoteSigned policy for the
CurrentUser scope means that in my user’s context the execution of local unsigned scripts is allowed (while remote scripts have to be signed).
You can switch to this policy by issuing this command in PowerShell:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
If you follow Tyler’s instructions you should be able to use virtualenv. You can switch to an environment with the
workon command and you can exit the current environment with the command
For more information about working with virtualenv have a look at this virtualenvwrapper command reference.
After Setting up virtualenv I wanted to install some packages that I usually Need, in particular numpy, scipy, matplotlib, pandas and iPython.
pip install numpy should work. But here it did not but pip stopped with an error message.
The SciPy.org page again recommends a pre-built distribution.
Alternatively it points to the maintainers of the single packages.
At this point I used the binary installers (Python 2.7 32bit) for numpy, scipy and matplotlib. The main reason were the recommendations to use the binary installer for matplotlib, also since the build instructions for Windows require Visual Studio compilers to be installed.
All three packages can be uninstalled from the Windows Control Panel/Programs and Features.
They install into the site-packages Directory so that virtualenv is not used. Since I usually always Need one of these packages this seemed acceptable for the time being.
But note that with this set-up there were still some errors when I tried to use matplotlib functions.
The six and pyparsing packages were missing.
Six is also needed for pandas and installed automatically as a dependency with it so I tried
pip install pandas. The Installation failed again due to the missing c Compiler.
Since I had Microsoft Visual Studio 2013 installed I investigated why the compiler is not being found by pip.
I turns out that the different Python versions are built with specific versions of Visual Studio and the according packages need the very same compiler version to work (Visual Studio 2008 for Python 2.7 and Visual Studio 2010 for Python 3.3). This information can be found in this StackExchange question. In the answers some people had success by linked the location of newer Visual Studio versions to the expected location of the required version.
SET VS90COMNTOOLS=%VS120COMNTOOLS% did not work. pip found the compiler but the Installation aborted with a compile error.
Reading the error message carefully solves the problem: It gives a link to an official Microsoft download for Visual C++. Microsoft kindly provides a Compiler specifically for Python 2.7 packages.
With this compiler the install via pip worked for pandas and also for iPython:
pip install pandas
pip install ipython[notebook]
In the screenshot you can see iPython successfully installing and starting.