簡體   English   中英

導入可在Python中工作,但不能在IPython中工作

[英]Import works in Python but not IPython

當我在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.
>>> import georasters
>>> from osgeo import gdal

ModuleNotFoundError當我做同樣的事情在一個IPython的終端:

$ 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'

為什么以及如何解決此問題? 我有一個MAC El Capitan和python 3.6.1。 我已經用conda install ...安裝了所有東西conda install ...謝謝。


conda list輸出

$ conda list
# packages in environment at /Users/<myname>/anaconda/envs/cv:
#
affine                    2.1.0                    py35_0    conda-forge
attrs                     17.2.0                   py35_0    conda-forge
boost                     1.64.0                   py35_3    conda-forge
boost-cpp                 1.64.0                        1    conda-forge
boto3                     1.4.4                    py35_0    conda-forge
botocore                  1.5.92                   py35_0    conda-forge
bzip2                     1.0.6                         1    conda-forge
ca-certificates           2017.7.27.1                   0    conda-forge
cairo                     1.14.6                        4    conda-forge
cartopy                   0.15.1              np112py35_2    conda-forge
certifi                   2017.7.27.1              py35_0    conda-forge
chardet                   3.0.2                    py35_1    conda-forge
click                     6.7                      py35_0    conda-forge
click-plugins             1.0.3                    py35_0    conda-forge
cligj                     0.4.0                    py35_0    conda-forge
cloudpickle               0.3.1                    py35_0    conda-forge
curl                      7.54.1                        0    conda-forge
cycler                    0.10.0                   py35_0    conda-forge
dask                      0.13.0                   py35_0    ozak
decorator                 4.1.2                    py35_0    conda-forge
descartes                 1.1.0                    py35_0    conda-forge
docopt                    0.6.2                    py35_0    conda-forge
docutils                  0.13.1                   py35_0    conda-forge
expat                     2.1.0                         3    conda-forge
fiona                     1.7.8                    py35_1    conda-forge
fontconfig                2.12.1                        4    conda-forge
freetype                  2.7                           1    conda-forge
freexl                    1.0.2                         2    conda-forge
gdal                      2.2.0               np112py35_2    conda-forge
geopandas                 0.2.1                    py35_4    conda-forge
geopy                     1.11.0                   py35_0    conda-forge
georasters                0.5.6                    py35_0    ozak
geos                      3.5.1                         1    conda-forge
gettext                   0.19.8.1                      0    conda-forge
giflib                    5.1.4                         0    conda-forge
glib                      2.51.4                        0    conda-forge
hdf4                      4.2.12                        0    conda-forge
hdf5                      1.8.18                        1    conda-forge
hypothesis                3.17.0                   py35_0    conda-forge
icu                       58.1                          1    conda-forge
idna                      2.5                      py35_0    conda-forge
imageio                   2.2.0                    py35_0    conda-forge
jmespath                  0.9.3                    py35_0    conda-forge
jpeg                      9b                            0    conda-forge
json-c                    0.12.1                        0    conda-forge
kealib                    1.4.7                         2    conda-forge
krb5                      1.14.2                        0    conda-forge
libdap4                   3.18.3                        2    conda-forge
libffi                    3.2.1                         3    conda-forge
libgdal                   2.1.4                         2    conda-forge
libgfortran               3.0.0                         0    conda-forge
libiconv                  1.14                          4    conda-forge
libkml                    1.3.0                         1    conda-forge
libnetcdf                 4.4.1.1                       6    conda-forge
libpng                    1.6.28                        1    conda-forge
libpq                     9.6.3                         0    conda-forge
libspatialindex           1.8.5                         1    conda-forge
libspatialite             4.3.0a                       15    conda-forge
libssh2                   1.8.0                         1    conda-forge
libtiff                   4.0.6                         7    conda-forge
libxml2                   2.9.4                         4    conda-forge
libxslt                   1.1.29                        5    conda-forge
lxml                      3.8.0                    py35_0    conda-forge
matplotlib                2.0.2                    py35_2    conda-forge
mkl                       2017.0.3                      0  
munch                     2.2.0                    py35_0    conda-forge
ncurses                   5.9                          10    conda-forge
networkx                  1.11                     py35_0    conda-forge
numpy                     1.12.1                   py35_0  
olefile                   0.44                     py35_0    conda-forge
openjpeg                  2.1.2                         2    conda-forge
openssl                   1.0.2l                        0    conda-forge
owslib                    0.14.0                   py35_0    conda-forge
pandas                    0.20.3                   py35_1    conda-forge
pcre                      8.39                          0    conda-forge
pillow                    4.2.1                    py35_1    conda-forge
pip                       9.0.1                    py35_0    conda-forge
pixman                    0.34.0                        0    conda-forge
poppler                   0.52.0                        2    conda-forge
poppler-data              0.4.7                         0    conda-forge
proj4                     4.9.3                         4    conda-forge
psycopg2                  2.7.3                    py35_0    conda-forge
pyepsg                    0.3.2                    py35_0    conda-forge
pympler                   0.5                      py35_0    conda-forge
pyparsing                 2.2.0                    py35_0    conda-forge
pyproj                    1.9.5.1                  py35_0    conda-forge
pysal                     1.13.0                   py35_0    conda-forge
pyshp                     1.2.11                   py35_0    conda-forge
python                    3.5.4                         0    conda-forge
python-dateutil           2.6.1                    py35_0    conda-forge
pytz                      2017.2                   py35_0    conda-forge
pywavelets                0.5.2               np112py35_0    conda-forge
rasterio                  0.36.0                   py35_0    conda-forge
rasterstats               0.11.0                   py35_0    ozak
readline                  6.2                           0    conda-forge
requests                  2.18.3                   py35_0    conda-forge
rtree                     0.8.3                    py35_0    conda-forge
s3transfer                0.1.10                   py35_1    conda-forge
scikit-image              0.13.0                   py35_1    conda-forge
scipy                     0.19.1              np112py35_0  
setuptools                36.2.2                   py35_0    conda-forge
shapely                   1.5.17                   py35_4    conda-forge
simplejson                3.11.1                   py35_0    conda-forge
six                       1.10.0                   py35_1    conda-forge
snuggs                    1.4.1                    py35_0    conda-forge
sqlalchemy                1.1.11                   py35_0    conda-forge
sqlite                    3.13.0                        1    conda-forge
tk                        8.5.19                        2    conda-forge
toolz                     0.8.2                    py35_0    conda-forge
tornado                   4.5.1                    py35_0    conda-forge
urllib3                   1.21.1                   py35_0    conda-forge
wheel                     0.29.0                   py35_0    conda-forge
xerces-c                  3.1.4                         3    conda-forge
xz                        5.2.2                         0    conda-forge
zlib                      1.2.8                         3    conda-forge
zope                      1.0                      py35_0  
zope.interface            4.4.2                    py35_0  

看起來您正在運行不同版本的Python(shell中為3.5.4,IPython中為3.6.1)。

您可以使用conda list列出活動環境中安裝的軟件包和版本。 我懷疑您是在其他環境中運行ipython 查看它是否已安裝在活動環境中。 如果您沒有在列表中看到它,請使用conda install -n {env_name} ipython

更新:在安裝后ipythonconda ,我總是需要source activate {env_name}再次。 安裝其他軟件包似乎不需要重新采購。

就我而言,問題是,正如tdube的回答一樣,不同版本的Python(shell中為2.7.15,IPython中為3.6.7)。 我已經使用pip安裝了軟件包,該軟件包已安裝為默認python (2.7):

pip install umap-learn      # Not accessible in my IPython

使用pip3將軟件包安裝在IPython可以訪問的位置,該位置在Python 3上。

pip3 install umap-learn     # Accessible in my IPython

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM