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

7

自从昨天开始,我一直在努力导入一些库,例如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.so

    /Library/Frameworks/GDAL.framework/Versions/2.1/Python/2.7/site-packages/osgeo/_gdal.so

今天早上我可以成功导入gdal,突然之间(我不知道我做了什么)就完全不可能了。

我尝试过:

  • 卸载/安装gdal
  • 卸载/安装anaconda并重新安装gdal
  • 创建不同的新环境(在python2和python3中),并只安装gdal

我不知道libicui18n.56.dylib是什么,也不知道libgdal.20.dylib是什么。

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

libicui18n.54.dylib (compatibility version 54.0.0, current version 54.1.0)
@loader_path/./libicuuc.54.dylib (compatibility version 54.0.0, current version 54.1.0)
@loader_path/./libicudata.54.dylib (compatibility version 54.0.0, current version 54.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

@rpath/libgdal.1.dylib (compatibility version 20.0.0, current version 20.5.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

/Library/Frameworks/GDAL.framework/Versions/2.1/GDAL (compatibility version 22.0.0, current version 22.1.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

当我输入conda info时:
           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

我在想图书馆是否保存在错误的目录中?

我看到了许多类似的问题,但没有解决问题的技巧。

谢谢您的帮助。

2个回答

5

我有同样的问题。

conda install -f jpeg=8

conda install libgdal

解决我的问题


4

我在这里找到了解决问题的方案

感谢您对“ocefpaf”的清晰解释:

你的问题似乎是conda-forge和defaults之间通常的不匹配。如果你确实想使用conda-forge的gdal,请尝试以下操作:

  1. 确保你有最新的conda以利用频道优先特性。你可以在conda安装的根环境中输入conda update conda来完成。

  2. 编辑你的.condarc文件,并将conda-forge放在defaults的顶部。.condarc通常位于你的主目录下。看看我的示例(请注意,你拥有的频道越多,你就越容易遇到问题。我建议只有默认值和conda-forge)。

  3. 发出以下命令检查是否会得到正确的安装:

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

如果您获得了2.1.1版本,则已成功安装了来自conda-forge的最新版本。我们始终建议用户像上面的示例一样使用envs。但是,您不需要使用Python 3.5(conda-forge也有3.4和2.7),也不需要将env命名为TEST_GDAL。下面是我的.condarc文件。
> cat .condarc
channels:
- conda-forge
- defaults
show_channel_urls: true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接