-3

I've been having difficulty with Python recently, mainly since I think I had several versions and conflicts (due to Anaconda installs, canopy installs etc.). So I cleaned those out.

I reinstalled python (2.7) via brew.

I reinstalled numpy and matplotlib via pip. I also reinstalled astropy and h5py via pip.

However, I get a clean import of numpy and matplotlib, but not of astropy and h5py:

~ > python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>> import astropy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named astropy
>>> import h5py
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ImportError: No module named h5py
>>> 
Suever
  • 64,497
  • 14
  • 82
  • 101
npross
  • 1,756
  • 6
  • 19
  • 38
  • 4
    Clearly you had not installed `astropy` and `h5py` in used interpreter. Check if `python -m pip list` lists `astropy` and `h5py`. `pip` may symlink to some other binary, not related to interpreter currently used by you. – Łukasz Rogalski Mar 23 '16 at 18:22
  • Make sure that the output of `which python` and `which pip` make sense, and that the output of ``head `which pip``` matches with `which python`. Make sure you understand everything that's in your `$PATH` and that that's logical to you. Remove anything that isn't meaningful. Same with `$PYTHONPATH` (in fact I would recommend completely clearing `$PYTHONPATH` and almost never using it--if you want an alternate install location for packages use virtualenv). – Iguananaut Mar 24 '16 at 09:22

1 Answers1

3

My suspicion is that your pip executable is not linked to your python executable, which means when you run pip install astropy it is installing it in the site-packages for a different python.

One way to make sure you're using the correct pip is to not use

$ pip install astropy

but instead use

$ python -m pip install astropy

If this fails, it probably means that you don't have pip installed for the python instance you're using, and you need to install it (note that for Python 2 version 2.7.9 or later, or Python 3 version 3.4 or later, pip comes bundled with Python).

If this still doesn't work, then something stranger is going on. It may be due to having $PYTHONPATH or $LD_LIBRARY_PATH/$DYLD_LIBRARY_PATH set in a way that interferes with your python imports. In this case, you could clear these variables and try again. Otherwise, I'd consider using a package bundle such as conda or canopy. It makes these kinds of installation issues much smoother.


Edit: I see now that you've used conda and canopy, and you suspect these were causing your problems. Conda and canopy, by design, both sandbox their python installations so that they shouldn't get interference from other installs in your system, unless you force such interference by setting the environment variables I mentioned above. I'd suggest reinstalling conda and wiping those environment variables from your bash/csh startup script.

jakevdp
  • 77,104
  • 11
  • 125
  • 160
  • @Rogalski I've tried "python -m pip install astropy" and "python -m pip list" and get "/usr/bin/python: No module named pip" in both cases, so something's not right there... – npross Mar 23 '16 at 19:23
  • It sounds like pip is not installed for /usr/bin/python. Try following the instructions at https://pip.pypa.io/en/stable/installing/ – jakevdp Mar 23 '16 at 22:20