在进行GDAL时出现问题:ImportError,未加载库,未找到图像

Zor*_*ran 5 python gdal importerror anaconda

从昨天开始,我很难导入一些像GDAL(或虹膜)这样的库,我总是得到相同类型的输出.

>>> 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
Run Code Online (Sandbox Code Playgroud)

我在我的文件中搜索并发现:

  • 包含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)
Run Code Online (Sandbox Code Playgroud)

当我键入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
Run Code Online (Sandbox Code Playgroud)

我想知道图书馆是否以某种方式保存在错误的目录中?

我已经看到很多类似的问题,但没有解决问题的技巧.

谢谢你的帮助

小智 5

我也有同样的问题。

conda install -f jpeg=8

conda install libgdal
Run Code Online (Sandbox Code Playgroud)

解决我的问题


Zor*_*ran 4

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

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

您的问题似乎是 conda-forge 和默认值之间通常不匹配的问题。您可以尝试以下说明(当然如果您确实想使用 conda-forge 的 gdal):

  1. 确保您拥有最新的 conda 以利用频道首选项功能。您可以通过在 conda 安装的根环境中发出 conda update conda 来完成此操作。

  2. 编辑 .condarc 文件并将 conda-forge 放在默认值之上。.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__)"
Run Code Online (Sandbox Code Playgroud)

如果您获得 2.1.1,则您已成功安装 conda-forge 的最新版本。我们始终建议用户使用 envs,如上面的示例所示。但您不需要使用 Python 3.5(conda-forge 也有 3.4 和 2.7),并且不需要将环境命名为 TEST_GDAL。

这是我的 .condarc 文件。

> cat .condarc
channels:
- conda-forge
- defaults
show_channel_urls: true
Run Code Online (Sandbox Code Playgroud)