Astropy不能与Python一起使用

时间:2016-03-23 18:18:41

标签: python numpy matplotlib pip astropy

我最近遇到了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
>>> 

1 个答案:

答案 0 :(得分:3)

我的怀疑是您的pip可执行文件未链接到您的python可执行文件,这意味着当您运行pip install astropy时,它会将其安装在网站中 - 不同 python的包。

确保使用正确点的一种方法是不使用

$ pip install astropy

但请改用

$ python -m pip install astropy

如果失败,可能意味着您没有为正在使用的python实例安装pip,并且需要install it(请注意,对于Python 2 2.7.9或更高版本,或者Python 3版本3.4或更高版本,pip与Python捆绑在一起。

如果这仍然不起作用,那么一些陌生人正在发生。这可能是由于$PYTHONPATH$LD_LIBRARY_PATH / $DYLD_LIBRARY_PATH的设置干扰了您的python导入。在这种情况下,您可以清除这些变量并重试。否则,我会考虑使用condacanopy等软件包。它使这些安装问题更加顺畅。

编辑:我现在看到你已经使用过康达和树冠,你怀疑这些都会导致你的问题。根据设计,Conda和遮篷都可以对它们的python安装进行沙箱安装,这样它们就不会受到系统中其他安装的干扰,除非你通过设置我上面提到的环境变量来强制进行干扰。我建议重新安装conda并从bash / csh启动脚本中擦除这些环境变量。