libgdal.so.20:未定义的符号

时间:2018-06-07 13:04:17

标签: python pycharm anaconda gdal

昨天代码正在运行但是当我今天运行我的代码时,会发生以下错误:

runfile('/media/mattes/data1/dataDMattes/Code/Python/PythonProgram/main.py', wdir='/media/mattes/data1/dataDMattes/Code/Python/PythonProgram')

Traceback (most recent call last):

File "<ipython-input-1-e8fdc416f3c8>", line 1, in <module>
runfile('/media/mattes/data1/dataDMattes/Code/Python/PythonProgram/main.py', wdir='/media/mattes/data1/dataDMattes/Code/Python/PythonProgram')

File "/home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "/home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/media/mattes/data1/dataDMattes/Code/Python/PythonProgram/main.py", line 17, in <module>
import ogr

File "/home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/site-packages/ogr.py", line 2, in <module>
from osgeo.gdal import deprecation_warn

File "/home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/site-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()

File "/home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)

File "/home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)

File "/home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)

ImportError: /home/mattes/anaconda3/envs/gmt-python2/lib/python3.6/site-packages/osgeo/../../../libgdal.so.20: undefined symbol: _ZN11xercesc_3_211InputSource11setEncodingEPKDs

我还尝试重新安装所有内容并再次安装gdallibgdal,但错误仍然存​​在。我使用的虚拟环境:

gdal                      2.2.4                    py36_0    conda-forge
libgdal                   2.2.4                hc8d23f9_1    anaconda

嗯,我知道这两个来自不同的来源,但直到昨天一直有效。

我在Ubuntu 16.04中使用Python 3.6.3和Anaconda。

更新

正如我发现的那样,当我使用PyCharm而不是Anaconda时,也会出现同样的错误。在这种情况下,我使用pip命令和预先安装的libgdal下载GDAL。

在这种情况下,这是错误消息:

Traceback (most recent call last):
File "/opt/pycharm-community-2018.1.4/helpers/pydev/pydev_run_in_console.py", line 52, in run_file
pydev_imports.execfile(file, globals, locals)  # execute the script
File "/opt/pycharm-community-2018.1.4/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/media/mattes/data1/dataDMattes/Code/Python/PythonProgram/main.py", line 18, in <module>
import ogr
File "/opt/pycharm-community-2018.1.4/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs)
File "/usr/lib/python3/dist-packages/ogr.py", line 2, in <module>
from osgeo.gdal import deprecation_warn
File "/opt/pycharm-community-2018.1.4/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs)
File "/opt/pycharm-community-2018.1.4/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs)
File "/usr/lib/python3/dist-packages/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
File "/usr/lib/python3/dist-packages/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: /usr/lib/libgdal.so.20: undefined symbol: _ZN11xercesc_3_111InputSource11setEncodingEPKt

对于PyCharm,我使用的是Python 3.5.2。

有人有想法吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

如果昨天有效,请尝试查看conda list --revisions -n gmt-python2以查看自此以来发生的变化。

我不认为Anaconda本身来自conda-forge频道的gdal和来自anaconda频道的libgdal。所以它必定发生在某个时刻。

您可以尝试使用其中一个频道强制Conda更新。使用GDAL我绝对更喜欢conda-forge构建,因为它(至少在过去)有更好的工作激活脚本,这些脚本在切换环境时也能正确设置GDAL_DATA环境变量。

conda install conda-forge::gdal=2.2.4 --force --update-dependencies