12

我正在这样做并收到此错误:

from gensim.models import Word2Vec

ImportError: cannot import name 'open' from 'smart_open' (C:\ProgramData\Anaconda3\lib\site-packages\smart_open\__init__.py)

然后我这样做了:

import smart_open
dir(smart_open)

['BZ2File','BytesIO','DEFAULT_ERRORS','IS_PY2','P','PATHLIB_SUPPORT','SSLError','SYSTEM_ENCODING','Uri','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__path__','__spec__','boto','codecs','collections','gzip','hdfs','http','importlib','io','logger','logging','os','pathlib','pathlib_module','requests','s3','s3_iter_bucket','six','smart_open','smart_open_hdfs','smart_open_http','smart_open_lib','smart_open_s3','smart_open_webhdfs','sys','urlparse','urlsplit','warnings','webhdfs']

如您所见,其中没有“开放”,所以我应该如何解决这个问题。我尝试安装不同的版本,我也升级了所有版本。

4

7 回答 7

26

我也遇到了同样的错误。我通过将 smart_open 更新到 2.0.0 版解决了这个问题。

conda install smart_open==2.0.0

或者

pip install smart_open==2.0.0.

于 2020-06-16T13:54:40.153 回答
9
import smart_open
smart_open.open = smart_open.smart_open
from gensim.models import Word2Vec

效果很好。

于 2021-02-28T02:46:19.407 回答
4

我遇到了同样的错误,我通过将 smart_open 升级到最新版本解决了这个错误:

conda update smart_open

或者

pip install --upgrade smart_open

于 2020-11-04T07:02:17.390 回答
2
\lib\site-packages\gensim\utils.py in <module>
     43 from six.moves import range
     44 
---> 45 from smart_open import open
     46 
     47 from multiprocessing import cpu_count

ImportError: cannot import name 'open'

smart_open 2.1.0 和 gensim 3.8.3 对我来说也是同样的问题。也是在down和升级之后。

于 2020-07-24T15:42:57.530 回答
1

有同样的问题。

gensim/utils.py:

改变:

from smart_open import open

至:

from smart_open import open

然后在文件中替换 opensmart_open,原因:

似乎smart_open将函数名称从 open 更改为smart_open

于 2021-02-19T07:30:11.720 回答
1

在 C:\ProgramData\Anaconda3\lib\site-packages\gensim\utils.py 中,我简单地更改from smart_open import openfrom smart_open import smart_open并且它工作。

于 2020-12-25T03:18:10.677 回答
0

从...开始

conda update smart_open

如果它不起作用去gensim/utils.py

并更换

from smart_open import open 

from smart_open import open
于 2021-07-09T23:41:20.840 回答