Reputation: 63082
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...
Upvotes: 2
Views: 10233
Reputation: 6581
Looking at your where
results, I think your ipython seems to look at the wrong path when trying to import modules.
The complete diagnose and fix (for you and future Googlers):
Use which
(Linux) or where
(windows) on your command prompt to check the pip
and python
/ipython
paths.
1.1. If the ipython seems to run from a different path, start it and check where the matching Python installation using import sys; sys.executable
.
Anyway, fix this problem by carefully modifying the PATH environment variable in a way that it will show the path to right Python executable.
Edit: After a bit of extra discussion with the OP (look @ comments), if the ipython installation isn't linked with the python executable, you should change the first line of your ipython file to shabang, then the path of your Python executable. It should look like: #!/usr/bin/python
when /usr/bin/python
is the path to the right Python executable.
Edit 2: Better solution for unlinked ipython would be to install ipython for the right Python version, using python -m pip install ipython
(thanks @abarnert and @koffein).
Upvotes: 2
Reputation: 365787
The ipython
script is just a very thin wrapper around the actual IPython module, installed into Python's site-packages.
Just changing its #!
line to point at a different Python is almost always a bad idea. That other Python may have a different IPython version in its site-packages/dist-packages, or may not have one at all.
Of course if you only want one ipython
, it's just a matter of installing it with the right version of Python, and not installing it for any other Python.
The problem most people run into is that they accidentally install it for two different Pythons, and whichever one they installed second (or, occasionally, whichever one ends up in a winning location on the PATH) ends up being the one they use, even though it's not the one they intended.
If you don't want IPython for that second Python version, just don't install it. Or, if you already did, uninstall it for both Python versions, then reinstall it for just the one you want.
What if you want IPython for multiple Python versions?
Unfortunately, they're all going to try to install with the same name, ipython
. Maybe ipython2
and ipython3
, but that only helps if your own two Python installations are one 2.x and one 3.x. If you have CPython 3.4 and PyPy 3.2, or a system-installed CPython 2.7 and a third-party CPython 2.7, that doesn't do you any good.
So, what can you do?
What I do is to make sure each Python (besides the system-installed one) is configured to use a scripts
/bin
directory that isn't on my PATH, then symlink things manually.
So, on both my Mac and Linux systems, ipython
and ipython2
both point at the system Python 2.7, and were installed just by sudo pip install ipython
. But ipython3
is a symlink that I manually created to where my main Python 3 installation installs binaries. And ipypy
and ipypy3
are symlinks to where my main PyPy 2.x and 3.x installations install binaries. (And these of course all parallel symlinks I created named python
, python2
, python3
, pypy
, and pypy3
.)
I did have to create these symlinks manually, but that's better than modifying the scripts.
Upvotes: 0
Reputation: 1882
Lets say you start the python console from the terminal with ipython
. If you want to ensure that you are installing the packages to the right python installation, use
sudo ipython -m pip install mpld3
So automatically the right pip (and the right paths) should be used.
Upvotes: 2
Reputation: 63082
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.
Upvotes: 0