Search code examples
pythonpip

pip install for mpld3


I just did a

 sudo pip install matplotlib

which worked fine. Then

 sudo pip install mpld3

Details:

$sudo pip install mpld3
Downloading/unpacking mpld3
  Downloading mpld3-0.2.tar.gz (1.1MB): 1.1MB downloaded
  Running setup.py (path:/private/tmp/pip_build_root/mpld3/setup.py) egg_info for package mpld3

Installing collected packages: mpld3
  Running setup.py install for mpld3

Successfully installed mpld3
Cleaning up...

So mpld3 also installed fine.

For some reason matplotlib is showing up in python, but not mpld3:

In [3]: import matplotlib.pyplot as plt

In [4]: plt.plot([3,1,4,1,5], 'ks-', mec='w', mew=5, ms=20)
Out[4]: [<matplotlib.lines.Line2D at 0x103ab4d10>]

In [5]: plt.show()

works fine ..

But:

In [6]: import mpld3
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-25a6968c2f16> in <module>()
----> 1 import mpld3

ImportError: No module named mpld3

Is it necessary to update e.g. PYTHONPATH or some other env var?

UPDATE Answering (good) question from @infinity about the pip vs ipython versions:

$which pip
/usr/local/Cellar/python/2.7.8_2/bin/pip
18:20:42/lightbox2 $which ipython
/usr/local/bin/ipython
18:20:45/lightbox2 $which python
/usr/local/Cellar/python/2.7.8_2/bin/python
18:23:58/lightbox2 $sudo pip install ipython
Password:
Requirement already satisfied (use --upgrade to upgrade): ipython in /Library/Python/2.7/site-packages
Cleaning up...

Solution

  • The ipython executable is hardcoded to /usr/bin/python. The best workaround I can see is to change the first line from

    #!/usr/bin/python
    

    to

    #!/usr/bin/env python
    

    That fixed the issue for my case of a non-standard python location.