The State of Python Package Management on Windows

September 12, 2017

Before I document the latest and greatest in Python package management, let me lay down the details of my environment:

In [3]:
import platform
import sys

print("""python version: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
""" % (
sys.version.split('\n'),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version()
))
python version: ['3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)]']
system: Windows
machine: AMD64
platform: Windows-10-10.0.14393-SP0
uname: uname_result(system='Windows', node='abhirag', release='10', version='10.0.14393', machine='AMD64', processor='Intel64 Family 6 Model 69 Stepping 1, GenuineIntel')
version: 10.0.14393

Now that we have the pesky details out of our way, let me explain what I am trying to do here. An year ago if you would have asked for my help in setting up a Python environment on Windows, I would have told you to go with the Anaconda distribution but I am not so sure anymore. To absolute beginners experimenting with the SciPy stack I would still recommend the Anaconda distribution, but to everyone else I would suggest pipenv, as it is now the officially recommended Python packaging tool from Python.org. The gains one can get from having Pipfile, pip, and virtualenv in one single toolchain are too big to ignore. Allow me to demonstrate that setting up a Python environment on Windows using pipenv, like most things in life, is not as good as your dreams, but also not as bad as it seems(and it is only going to get better):

NumPy

Works like a charm!

In [1]:
!pipenv install numpy
Installing numpy...
Collecting numpy
  Downloading numpy-1.13.1-cp36-none-win_amd64.whl (7.8MB)
Installing collected packages: numpy
Successfully installed numpy-1.13.1

Adding numpy to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

Pandas

Works like a charm!

In [2]:
!pipenv install pandas
Installing pandas...
Collecting pandas
  Downloading pandas-0.20.3-cp36-cp36m-win_amd64.whl (8.3MB)
.
.
Installing collected packages: pytz, pandas
Successfully installed pandas-0.20.3 pytz-2017.2

Adding pandas to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

Matplotlib

Works like a charm!

In [3]:
!pipenv install matplotlib
Installing matplotlib...
Collecting matplotlib
  Downloading matplotlib-2.0.2-cp36-cp36m-win_amd64.whl (8.9MB)
.
.
Successfully installed cycler-0.10.0 matplotlib-2.0.2 pyparsing-2.2.0

Adding matplotlib to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

SciPy

I have some good news and some bad news, the bad news is that we don't have binary wheels for SciPy on Windows yet, so installation through pipenv fails:

In [4]:
!pipenv install scipy
Installing scipy...
.
.
Error:  An error occurred while installing scipy!
  Failed building wheel for scipy

The good news is that pre-release binary wheels for SciPy on Windows 32-bit & 64-bit are now available. Currently, the plans are that binary wheels for Windows will also be provided for future releases on PyPi, so installation through pipenv should work once that happens. You can track the progress of this effort on the corresponding github issue. Meanwhile this works fine(unfortunately our Pipfile and Pipfile.lock no longer represent the environment in its entirity):

In [5]:
!pip install -f https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com/ --pre scipy
Collecting scipy
  Downloading https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com/scipy-1.0.0.dev0+20170904140241_4f0ac18-cp36-none-win_amd64.whl (30.8MB)
Requirement already satisfied: numpy>=1.8.2 in c:\users\abhirag\.virtualenvs\root_env-9_gqt-7e\lib\site-packages (from scipy)
Installing collected packages: scipy
Successfully installed scipy-1.0.0.dev0+4f0ac18

SymPy

Works like a charm!

In [6]:
!pipenv install sympy
Installing sympy...
.
.
Installing collected packages: mpmath, sympy
Successfully installed mpmath-0.19 sympy-1.1.1

Adding sympy to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

IPython, Jupyter

This article is just a Jupyter Notebook exported to html, testament enough to them working like a charm!

In [7]:
!pipenv install ipython
Installing ipython...
.
.
Adding ipython to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!
In [8]:
!pipenv install jupyter
Installing jupyter...
.
.
Adding jupyter to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

Nose

Works.

In [9]:
!pipenv install nose
Installing nose...
Collecting nose
  Downloading nose-1.3.7-py3-none-any.whl (154kB)
Installing collected packages: nose
Successfully installed nose-1.3.7

Adding nose to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

Seaborn

You guessed it right, works just fine.

In [10]:
!pipenv install seaborn
Installing seaborn...
Collecting seaborn
.
.
Successfully built seaborn
Installing collected packages: seaborn
Successfully installed seaborn-0.8.1

Adding seaborn to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

Statsmodels

Depends on SciPy, so pipenv install fails, but once SciPy wheels for Windows land on PyPi progress on this should be unblocked. You can track the progress of this effort on the corresponding github issue.

In [11]:
!pipenv install statsmodels
Installing statsmodels...
.
.  
Error:  An error occurred while installing statsmodels!
  Failed building wheel for statsmodels

As a workaround, you can use the unofficial Windows binary wheels for statsmodels:

In [12]:
!pip install statsmodels-0.8.0-cp36-cp36m-win_amd64.whl
Processing c:\users\abhirag\documents\pipenv\root_env\statsmodels-0.8.0-cp36-cp36m-win_amd64.whl
Installing collected packages: statsmodels
Successfully installed statsmodels-0.8.0

Miscellaneous

A bunch of other packages which are part of my environment:

In [13]:
!pipenv install beautifulsoup4
Installing beautifulsoup4...
Collecting beautifulsoup4
  Downloading beautifulsoup4-4.6.0-py3-none-any.whl (86kB)
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.6.0

Adding beautifulsoup4 to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!
In [14]:
!pipenv install lxml
Installing lxml...
Collecting lxml
  Downloading lxml-3.8.0-cp36-cp36m-win_amd64.whl (3.2MB)
Installing collected packages: lxml
Successfully installed lxml-3.8.0

Adding lxml to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!
In [16]:
!pipenv install plotly
Installing plotly...
Collecting plotly
.
.
Installing collected packages: urllib3, chardet, idna, certifi, requests, plotly
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 plotly-2.0.15 requests-2.18.4 urllib3-1.22

Adding plotly to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!
In [18]:
!pipenv install bokeh
Installing bokeh...
Collecting bokeh
.
.
Installing collected packages: PyYAML, bkcharts, bokeh
Successfully installed PyYAML-3.12 bkcharts-0.2 bokeh-0.12.7

Adding bokeh to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!
In [19]:
!pipenv install folium
Installing folium...
Collecting folium
.
.
Installing collected packages: branca, folium
Successfully installed branca-0.2.0 folium-0.4.0

Adding folium to Pipfile's [packages]...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!
In [20]:
!pipenv install requests
Installing requests...
.
.
Adding requests to Pipfile's [packages]...
P.S. You have excellent taste!
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock!

Conclusion

Thanks to the hard work of a lot of people in the Python community the Python package management story on Windows is much better now. I'll be switching over to pipenv and will try and contribute to its development, I hope you do too.

In [15]:
%matplotlib inline 
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from numpy import vectorize
from matplotlib.colors import LinearSegmentedColormap

def plot(k):
    @vectorize
    def tupper(x,y):
        return (y // 17 // 2 ** (17 * int(x) + int(y) % 17)) % 2 > 0.5
    custom_cmap = LinearSegmentedColormap.from_list('taxi_driver', ['gold','black'])
    X, Y = np.meshgrid(range(106), range(k, k + 17))
    Z = np.fliplr(tupper(X, Y))
    plt.figure(figsize = (106,17))
    plt.imshow(Z, interpolation='nearest', cmap = custom_cmap)
    plt.show()

k = 95500182201516581983920832671714565770426455565039891778737160107385569229269004\
793065306017186042923264556239058871166553957021501919629853468637788806704019867929\
944870261186178167391177949556483433038129626397447270622316936946925721496748773641\
203162582493261712599174437744370033500589089755659572871168
plot(k)