导入在Python中工作,但在IPython中不工作
在python终端中导入时没有问题:导入在Python中工作,但在IPython中不工作,python,macos,ipython,anaconda,osx-elcapitan,Python,Macos,Ipython,Anaconda,Osx Elcapitan,在python终端中导入时没有问题: $ python Python 3.5.4 | packaged by conda-forge | (default, Aug 10 2017, 01:41:15) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>&
$ python
Python 3.5.4 | packaged by conda-forge | (default, Aug 10 2017, 01:41:15)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import georasters
>>> from osgeo import gdal
$ ipython
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
Type "copyright", "credits" or "license" for more information.
IPython 5.3.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import georasters
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-5a74495660ba> in <module>()
----> 1 import georasters
ModuleNotFoundError: No module named 'georasters'
In [2]: from osgeo import gdal
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-a04b80bf4e65> in <module>()
----> 1 from osgeo import gdal
ModuleNotFoundError: No module named 'osgeo'
ModuleNotFoundError
当我在ipython终端中执行相同操作时:
$ python
Python 3.5.4 | packaged by conda-forge | (default, Aug 10 2017, 01:41:15)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import georasters
>>> from osgeo import gdal
$ ipython
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
Type "copyright", "credits" or "license" for more information.
IPython 5.3.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import georasters
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-5a74495660ba> in <module>()
----> 1 import georasters
ModuleNotFoundError: No module named 'georasters'
In [2]: from osgeo import gdal
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-a04b80bf4e65> in <module>()
----> 1 from osgeo import gdal
ModuleNotFoundError: No module named 'osgeo'
看起来您正在运行不同版本的Python(shell中的3.5.4和IPython中的3.6.1) 您可以使用
conda list
列出活动环境中安装的软件包和版本。我怀疑您正在从不同的环境运行ipython
。查看它是否安装在活动环境中。如果在列表中看不到它,请使用conda install-n{env_name}ipython
安装它
更新:使用
conda
安装ipython
后,我始终需要再次源代码激活{env_name}
。安装其他软件包似乎不需要重新采购。在我的例子中,问题是,正如tdube的回答一样,Python的不同版本(shell中的2.7.15版本和IPython中的3.6.7版本)。我使用pip
安装了我的软件包,它是为默认的python
(2.7)安装的:
使用pip3
将软件包安装在python3上的IPython可以访问的位置
pip3 install umap-learn # Accessible in my IPython
看起来您有两个不同的python安装,您正在寻找的模块只对一个可用。太好了,谢谢!现在我该怎么办?看看你的$PATH,运行
哪个python
和哪个ipython
,等等。也许你有不同的conda安装程序?谢谢$python
提供给/Users//anaconda/envs/cv/bin/python
<代码>$ipython提供给/Users//anaconda/bin/ipython
。现在怎么办?根据conda list
,您缺少ipython
(可能还有其他软件包)。您需要使用conda install-n{your env name}ipython
安装它。我尝试了$conda install-n ipython
但它没有解决问题。。。。然后我做了source去激活
,接着是source激活
,它成功了。谢谢是的,我正打算这么说!由于某些原因,当您在conda环境中安装ipython
时,确实需要重新获取源代码。抢手货