Python 3.6: ImportError: cannot import name 'config' when trying to import gensim

Python 3.6: ImportError: cannot import name 'config' when trying to import gensim

我是运行最新版本Python:

'3.6.5 |Anaconda custom (64-bit)| (default, Mar 29 2018, 13:14:23) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]'

尝试像这样导入 gensim 时:

from gensim.corpora import Dictionary
import numpy as np

我收到以下错误:

/anaconda/lib/python3.6/site-packages/boto/provider.py in <module>()
     32 
     33 import boto
---> 34 from boto import config
     35 from boto.compat import expanduser
     36 from boto.pyami.config import Config

ImportError: cannot import name 'config'

我已尝试更新 Python、所有软件包及其依赖项,等等。似乎没有任何效果。

有什么想法吗?

我最近也碰到了类似的问题如下:

/anaconda2/lib/python2.7/site-packages/boto3/session.py in <module>()
     16 
     17 import botocore.session
---> 18 from botocore.client import Config
     19 from botocore.exceptions import DataNotFoundError, UnknownServiceError
     20 

ImportError: cannot import name Config

根据我的经验,它的根源在于你的conda环境中包的依赖冲突。所以我的解决方法如下:

  1. 完全删除 Anaconda。 (参见
  2. 从头开始重新安装 Anaconda(参见 here
  3. 使用 conda install -c anaconda gensim 命令安装 Gensim

需要说明的是,为了避免以后出现类似的问题,您应该尝试为 conda 创建不同的环境变量,因为它使包彼此分开,因此不会发生包冲突。您可以看到 this post 清楚地解释了如何在开始不同的项目之前创建这样的环境

希望对您有所帮助。