【发布时间】:2016-07-11 04:41:09
【问题描述】:
我最近在使用 Python 时遇到了困难,主要是因为我认为我有几个版本和冲突(由于 Anaconda 安装、canopy 安装等)。所以我清理了那些。
我通过 brew 重新安装了 python (2.7)。
我通过 pip 重新安装了 numpy 和 matplotlib。 我还通过 pip 重新安装了 astropy 和 h5py。
但是,我得到了 numpy 和 matplotlib 的干净导入,但没有 astropy 和 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
>>>
【问题讨论】:
-
显然你没有在使用的解释器中安装
astropy和h5py。检查python -m pip list是否列出astropy和h5py。pip可能符号链接到其他二进制文件,与您当前使用的解释器无关。 -
确保
which python和which pip的输出有意义,并且``headwhich pip``` matches withwhich python. Make sure you understand everything that's in your$PATH` 的输出对你来说是合乎逻辑的。删除任何没有意义的东西。与$PYTHONPATH相同(事实上,我建议完全清除$PYTHONPATH并且几乎从不使用它——如果您想要使用virtualenv 的包的备用安装位置)。
标签: python numpy matplotlib pip astropy