I wanted to use iPython Notebook in Python 3 on Ubuntu 14.04. Because I have both Python 2.7 and Python 3.4 installed on my system--and for other implementation-specific reasons--I decided to use a Python virtual environment (with
virtualenv). Very little has been written about this topic so far...
- How to install Python package pyzmq properly?
- How to install the latest IPython notebook in Ubuntu 12.04?
These reports don't specifically handle Python 3 and virtual environments. Furthermore, the the official and various unofficial guides to installing iPython Notebook don't deal with this use case, either.
The main problem I encountered is with the ZMQ library. To install the library and the Python bindings system-wide I used
sudo apt-get install libzmq3 libzmq3-dev python3-zmq
But when I tried
pip install ipython[notebook], either inside or outside my
virtualenv, the installation would fail with exit status 1 and the warnings:
Warning: Detected ZMQ version: 4.0.4, but pyzmq targets ZMQ 4.0.5. Warning: libzmq features and fixes introduced after 4.0.4 will be unavailable.
I confirmed in Synaptic Package Manager that the
libzmq3 package for Ubuntu is only version 4.0.4. As an alternative, I tried this fix, having
pyzmq build its own
pip install pyzmq --install-option="--zmq=bundled"
But this failed because it couldn't find a certain header file:
buildutils/initlibsodium.c:10:20: fatal error: Python.h: No such file or directory #include "Python.h" ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Next, I built
libzmq version 4.0.5 from source.
wget http://download.zeromq.org/zeromq-4.0.5.tar.gz tar -xzvf zeromq-4.0.5.tar.gz && rm zeromq-4.0.5.tar.gz cd /usr/local/zmq/zeromq-4.0.5 ./configure make -j 6 sudo make install
No problems encountered. After this, I tried to install
pyzmq in my virtual environment with:
I also tried building
pyzmq from source. In both cases, I could see from the output that the proper ZMQ version (4.0.5) was detected, but the installation failed because I didn't have Cython installed (a not-well-documented dependency for building
pyzmq, in my opinion).
After installing Cython for Python 3...
sudo apt-get install cython3
I tried installing
pyzmq again with
pip and with
easy_install both inside and outside the virtual environment; it still didn't work. This message was delivered despite
cython3 being installed:
Fatal: Cython-generated file 'zmq/backend/cython/_device.c' not found. Cython >= 0.16 is required to compile pyzmq from a development branch. Please install Cython or download a release package of pyzmq.
And this file structure:
$ ls -l zmq/backend/cython/ checkrc.pxd context.pxd __init__.py _poll.pyx utils.pxd constant_enums.pxi context.pyx libzmq.pxd rebuffer.pyx utils.pyx constants.pxi _device.pyx message.pxd socket.pxd _version.pyx constants.pyx error.pyx message.pyx socket.pyx