September 12, 2017
Before I document the latest and greatest in Python package management, let me lay down the details of my environment:
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()
))
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):
Works like a charm!
!pipenv install numpy
Works like a charm!
!pipenv install pandas
Works like a charm!
!pipenv install matplotlib
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:
!pipenv install 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):
!pip install -f https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com/ --pre scipy
Works like a charm!
!pipenv install sympy
This article is just a Jupyter Notebook exported to html, testament enough to them working like a charm!
!pipenv install ipython
!pipenv install jupyter
Works.
!pipenv install nose
You guessed it right, works just fine.
!pipenv install seaborn
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.
!pipenv install statsmodels
As a workaround, you can use the unofficial Windows binary wheels for statsmodels:
!pip install statsmodels-0.8.0-cp36-cp36m-win_amd64.whl
A bunch of other packages which are part of my environment:
!pipenv install beautifulsoup4
!pipenv install lxml
!pipenv install plotly
!pipenv install bokeh
!pipenv install folium
!pipenv install requests
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.
%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)