导入GDAL时出现问题:ImportError,未加载库,找不到图像

2024-10-04 03:26:29 发布

您现在位置:Python中文网/ 问答频道 /正文

从昨天开始,我一直在努力导入一些库,比如GDAL(或iris),而且我总是得到相同类型的输出。在

>>> import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gdal.py", line 28, in <module>
    _gdal = swig_import_helper()
  File "gdal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(./_gdal.so, 2): Library not loaded: @rpath/libicui18n.56.dylib
  Referenced from: /Users/zoran/anaconda/lib/libgdal.20.dylib
  Reason: image not found

我在我的档案里找到了:

  • 1个包含libicui18n的文件
  • 2个包含_gdal.so的文件

    /Users/zoran/anaconda/pkgs/icu-54.1-0/lib/libicui18n.54.1.dylib

    /Users/zoran/anaconda/lib/python2.7/site-packages/osgeo/_格达尔。索在

    /库/框架/GDAL.framework/Versions/2版.1/Python/2.7/site-packages/osgeo/_格达尔。索

今天早上我可以毫无问题地导入gdal,但突然(我不知道我做了什么)这是完全不可能的。在

我试着: -卸载/安装gdal -卸载/安装anaconda并重新安装gdal -创建不同的新环境(在python2和python3中)并只安装gdal

我不知道这是什么,不知道。在

当我用上面路径的名称键入otool-L时,我得到:

^{pr2}$

当我输入conda信息时:

           platform : osx-64
      conda version : 4.2.9
   conda is private : False
  conda-env version : 4.2.9
conda-build version : 2.0.2
     python version : 2.7.12.final.0
   requests version : 2.11.1
   root environment : /Users/zoran/anaconda  (writable)
default environment : /Users/zoran/anaconda
   envs directories : /Users/zoran/anaconda/envs
      package cache : /Users/zoran/anaconda/pkgs
       channel URLs : https://conda.anaconda.org/anaconda/osx-64/
                      https://conda.anaconda.org/anaconda/noarch/
                      https://conda.anaconda.org/scitools/osx-64/
                      https://conda.anaconda.org/scitools/noarch/
                      https://conda.anaconda.org/conda-forge/osx-64/
                      https://conda.anaconda.org/conda-forge/noarch/
                      https://repo.continuum.io/pkgs/free/osx-64/
                      https://repo.continuum.io/pkgs/free/noarch/
                      https://repo.continuum.io/pkgs/pro/osx-64/
                      https://repo.continuum.io/pkgs/pro/noarch/
        config file : /Users/zoran/.condarc
       offline mode : False

我想知道是不是这些库保存在错误的目录中?在

我见过许多类似的问题,但没有解决问题的诀窍。在

谢谢你的帮助


Tags: httpsioorgimportversionrepoanacondaconda
2条回答

我也有同样的问题。在

conda install -f jpeg=8

conda install libgdal

解决我的问题

我找到了解决问题的办法。在

感谢您对“ocefpaf”的明确解释:

You problem seems like the usuall mismatch between conda-forge and defaults. Can you try the following instructions (if you do want to use conda-forge's gdal of course):

  1. Make sure you have the latest conda to take advantage of the channel preference feature. You can do that by issuing conda update conda in the root env of your conda installation.

  2. Edit your .condarc file and place the conda-forge on top of defaults. The .condarc usually lives in your home directory. See mine below. (Note that the more channels you have you are more likely to face issues. I recommend having only defaults and conda-forge.)

  3. Issue the following commands to check if you will get the correct installation:

conda create  yes -n TEST_GDAL python=3.5 gdal
source activate TEST_GDAL
python -c "from osgeo import gdal; print(gdal.__version__)"

If you get 2.1.1 you got a successful installation of the latest version from conda-forge. We always recommend users to work with envs as the the example above. But you do not need to use Python 3.5 (conda-forge has 3.4 and 2.7 also) and you do not need to name the env TEST_GDAL.

And here is my .condarc file.

^{pr2}$

相关问题 更多 >