My python setup on Windows 10

Published 1/10/2018 11:29:01 AM
Filed under Python

Setting up a proper development environment for Python and Data Science projects can be hard on Windows. Python's origin isn't on Windows which shows, but you can get it to work with just a few tweaks. Here's how.

Use anaconda

For my work on AI projects I require tools like scipy, sklearn and tensorflow. These packages require native C math libraries. On Linux these math libraries are installed in your OS so you don't have to worry about them. On Windows however you need to install them yourself.

Intel offers MKL but it's quite a bit of work to get it installed and working with Python.

So instead of wrangling with MKL I download Anaconda with Python 3.6 included.

Why Python 3.6? Well, most of the stuff that is written today is for Python 3. Also, Ptyhon 2.7 is the last version of Python in the 2.x series. So I moved on to Python 3 and didn't look back.

Include anaconda in your Path

Now before you get click-happy and install Anaconda by clicking next as fast as you can. Please make sure you include Anaconda in your PATH variable. You can check this option in the installer.

I don't like having to start separate terminal sessions to access anaconda and then have to move back to my regular terminal to perform git operations or silliness similar to that.

That's why I include Anaconda in my PATH variable.

Use separate anaconda environments

Once you have anaconda installed, don't mess up your installation with all sorts of packages. Make a separate environment for each project you have.

You can do this by executing the following command:

conda create --prefix C:\virtualenvs\<environment name> python=3.5 pip

By using a prefix you get to locate the environment in a spot where you can find it on disk. I do this so that I can quickly clean things up if I break my setup.

Also note that I include a python=... parameter. This allows you to control the version of python you're running. Tensorflow for example requires python 3.5 instead of the python 3.6 that comes with the anaconda installation.

I also included pip as a parameter in the command. Both the python and pip parameters are names of packages you want included in your environment.

Anaconda has its own package manager that contains a lot of packages. Which is where the python and pip package are coming from.

But as any regular python developer will know, pip contains far more packages and is more up-to-date than the anaconda package system.

That is the reason why I always include pip in my anaconda environment.

To use the environment you need to execute the following command:

activate C:\virtualenvs\<environment name>

Once active you can install packages in your environment and work with it like it's a regular python installation.

When you're done, you can deactivate the environment using the following command:

deactivate

Fix Powershell interaction with Anaconda

When you work on Windows 10 with Powershell you will quickly notice that you can't activate an anaconda environment. This comes from the fact that there's no support for Powershell in Anaconda yet.

You can fix this however by installing the the pscondaenvs package from this repository

In short it comes down to this command:

conda install -n root -c pscondaenvs pscondaenvs

After that you can use the activate/deactivate commands as normal.

Happy hacking!

And that's it for my Python installation on Windows 10. If you're looking for editors to work on Python scripts I can recommend the following tools:

Happy hacking!