Python on Windows 8.1

Written by . Filed under Programming, Python, Windows. Bookmark the Permalink. Post a Comment. Leave a Trackback URL.

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.

Some sites (like SciPy.org or iPython.org) recommend going with a specialised Distribution like anaconda on Windows Systems.

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:

  1. Python 2 or Python 3?
  2. 32bit or 64bit?

You will have to answer these for youself, based on your particular requirements.
Help for you decision can be found on the python.org wiki site or
on this DataNitro blog entry.

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:

Get-ExecutionPolicy -List

My policies look like this:

Scope            ExecutionPolicy
-----            ---------------
MachinePolicy    Undefined
UserPolicy       Undefined
Process          Undefined
CurrentUser      RemoteSigned
LocalMachine     Undefined

The 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 deactivate.
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.
Usually a 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.
For me 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]

Installing iPython package under Windows 8.1

Installing iPython package under Windows 8.1

In the screenshot you can see iPython successfully installing and starting.

Be Sociable, Share!
  • Twitter
  • Facebook
  • email
  • StumbleUpon
  • Delicious
  • Google Reader
  • LinkedIn
  • BlinkList

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>