Installing IPython
For our new project we are trying to use Python 3, so I want to evaluate IPython on the latest version of Python, which currently is 3.4.3. I am using pyenv and pyvirtualenv to manage my python installs. So with those all set up, I installed python 3.4.3 and created a virtualenv to use for ipython.
pyenv install 3.4.3
pyenv virtualenv 3.4.3 ipython-3.4.3
mkdir ~/Code/ipython
cd ~/Code/ipython
echo 'ipython-3.4.3' > .python-version
pip install --upgrade ipython
# the pip install above gave me messages about upgrading pip, so I did:
pip install --upgrade pip
I haven’t used IPython before - or should I say Jupyter since that is the project’s new name. So I watched a couple of the introductory videos I found on YouTube. This video told me I needed to add the python 3 kernel to jupyter, so I tried to do that but kept getting messages about missing pieces every time I tried to run ipython.
$ ipython3 kernelspec install-self
# error message about not having pyzmq
$ pip install pyzmq
$ ipython3 kernelspec install-self
$ pip freeze
gnureadline==6.3.3
ipython==3.1.0
pyzmq==14.6.0
$ ipython
ImportError: No module named 'jinja2'
$ pip install jinja2
ImportError: No module named 'tornado'
$ pip install tornado
$ ipython
IPython notebook format depends on the jsonschema package:
$ pip install jsonschema
$ pip freeze
certifi==2015.4.28
gnureadline==6.3.3
ipython==3.1.0
Jinja2==2.7.3
jsonschema==2.4.0
MarkupSafe==0.23
pyzmq==14.6.0
tornado==4.1
What I had overlooked was an install target that would install not only ipython but all the things it typically depends on / uses. Once I installed ‘all’ I got a usable ipython.
$ pip install ipython[all]
$ pip freeze
alabaster==0.7.4
Babel==1.3
certifi==2015.4.28
docutils==0.12
gnureadline==6.3.3
ipython==3.1.0
Jinja2==2.7.3
jsonschema==2.4.0
MarkupSafe==0.23
mistune==0.5.1
nose==1.3.6
numpydoc==0.5
ptyprocess==0.4
Pygments==2.0.2
pytz==2015.2
pyzmq==14.6.0
requests==2.7.0
six==1.9.0
snowballstemmer==1.2.0
Sphinx==1.3.1
sphinx-rtd-theme==0.1.8
terminado==0.5
tornado==4.1
Exporting from IPython to other formats
One of the things we are most interested in for work is the export
formats that IPython / Jupyter supports so I tried out all the export
formats. The PDF renderer was looking for pandoc. According to the
pandoc install instructions,
before I can install pandoc, I need a version of LaTeX for the
Mac. So, I installed MacTeX from their
MacTeX.pkg. And then I installed pandoc with homebrew: brew install
pandoc
. I still can’t export PDFs from the drop down menu in the
iPython web interface:
nbconvert failed: command could not be found pdflatex
However, from the command line, I can convert my test document to latex:
$ ipython nbconvert --to latex --template article CNKTest.ipynb
produces the file CNKTest.tex which I can open and view in Latexit (which came from MacTeX).
Matplotlib
Some of the things I am playing aroud with want matplotlib - which
does not appear to be installed in my virtualenv. So I ran pip
install matplotlib
which says it did:
Installing collected packages: python-dateutil, numpy, pyparsing, matplotlib
Successfully installed matplotlib-1.4.3 numpy-1.9.2 pyparsing-2.0.3 python-dateutil-2.4.2
And now I can load matplotlib inside a running ipython session with
%matplotlib
(or I could load it when I start the session using
the command line argument: ipython --matplotlib