2
votes

On Ubuntu 15.04, I had ipython2 installed correctly and working with notebook, under the condition that I added "/usr/local/lib/python2.7/dist-packages" to the PYTHONPATH.

Now, I installed python3 and ipython3. ipython3 notebook works perfectly (provided I remove the above reference from the pythonpath). But ipython2 notebook returns

Could not start notebook. Please install ipython-notebook

regardless of the PYTHONPATH.

I have python2 and python3 installed in /usr/bin/ and ipython2 and ipython3 installed in /usr/local/bin. The ipythons were installed with pip and pip3.

Now, if I do install ipython-notebook, it installs (I think) another ipython in /usr/bin, which also doesn't work.

This is a bit confusing, in other words I have a mess of python distributions. Next time I should use anaconda, I know. But at the moment I would like to stick to this. How do I make it work?

1

1 Answers

5
votes

It is rare that you should set PYTHONPATH at all except for advanced use cases, and you should never set PYTHONPATH to a standard directory that's already on sys.path for one version of Python. The only thing that can do is break Python, especially versions other than the one for which that directory is already used.

How are you installing ipython-notebook?

To install the notebook with pip, do:

pip3 install notebook
jupyter notebook

Take note of the paths where that command has installed files. It will likely be in /usr/local.

If you are getting a different version of IPython than you expect, then there could be an easy-install.pth messing up your import path. A common problem caused by old and broken setuptools. You can test this with:

python3 -c 'import IPython; print(IPython.__file__)'

and/or

python3 -m site # shows your sys.path

If you see lines starting with /usr/lib in usr/local/lib/pythonX.Y/dist-packages/easy-install.pth, remove them, they can cause the wrong versions of packages to be imported.

Often, the easiest way to be sure is to remove all versions of a package and start again. You can try pip uninstall ipython, and keep repeating until it says there's no version installed. You may also have installed IPython with apt-get, in which case you can remove it with apt-get remove ipython. Once you are confident that there is no IPython on your system, you can install again with

python2 -m pip install ipython
python3 -m pip install ipython

(if you want it for both Legacy Python and Python 3)