这个是Anaconda的环境错误,我在安装basemap模块的时候,使用了两种方式,结果Anaconda的conda-forge
和anaconda
两个channel
出现了混合错误。参考这个链接:https://conda-forge.org/docs/user/tipsandtricks.html#how-to-fix-it
conda install basemap # 这种方式安装失败
conda install -c conda-forge basemap # 这种方式安装成功
执行完这两条命令以后就复现了上述错误。
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.6.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import gdal
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-ee38efafc30b> in <module>
----> 1 import gdal
~/anaconda3/lib/python3.7/site-packages/gdal.py in <module>
1 # import osgeo.gdal as a convenience
----> 2 from osgeo.gdal import deprecation_warn
3 deprecation_warn('gdal')
4
5 from osgeo.gdal import *
~/anaconda3/lib/python3.7/site-packages/osgeo/__init__.py in <module>
24 fp.close()
25 return _mod
---> 26 _gdal = swig_import_helper()
27 del swig_import_helper
28 else:
~/anaconda3/lib/python3.7/site-packages/osgeo/__init__.py in swig_import_helper()
20 if fp is not None:
21 try:
---> 22 _mod = imp.load_module('_gdal', fp, pathname, description)
23 finally:
24 fp.close()
~/anaconda3/lib/python3.7/imp.py in load_module(name, file, filename, details)
240 return load_dynamic(name, filename, opened_file)
241 else:
--> 242 return load_dynamic(name, filename, file)
243 elif type_ == PKG_DIRECTORY:
244 return load_package(name, filename)
~/anaconda3/lib/python3.7/imp.py in load_dynamic(name, path, file)
340 spec = importlib.machinery.ModuleSpec(
341 name=name, loader=loader, origin=path)
--> 342 return _load(spec)
343
344 else:
ImportError: libkea.so.1.4.7: cannot open shared object file: No such file or directory
解决办法
$ conda config --set channel_priority strict
执行这条命令会在~/.condarc
这个文件中添加以下内容:
channel_priority: strict
channels:
- conda-forge
- defaults
这样,在安装包的时候,Anaconda会优先在conda-forge的通道中查找,只有conda-forge中没有这个包存在的时候,才去anaconda/moniconda的通道去查找。这样子两个通道的包就不会发生混合。
注意!!!!!原来的环境基本无法修复,需要重新创建一个环境。
$ conda create -n new_env
$ source activate new_env