【问题标题】:cannot import name 'open' from 'smart_open'无法从“smart_open”导入名称“open”
【发布时间】:2020-09-22 15:25:34
【问题描述】:

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

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']

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

【问题讨论】:

    标签: deep-learning nlp importerror gensim


    【解决方案1】:

    开始

    conda update smart_open
    

    如果不起作用,请转到gensim/utils.py

    替换

    from smart_open import open 
    

    from smart_open import open
    

    【讨论】:

    • 我想你忘了把 ___ 改成 ___ 行。
    【解决方案2】:
    import smart_open
    smart_open.open = smart_open.smart_open
    from gensim.models import Word2Vec
    

    效果很好。

    【讨论】:

    • 这对我有用。
    【解决方案3】:

    遇到同样的问题。

    gensim/utils.py:

    更改:

    from smart_open import open
    

    收件人:

    from smart_open import open
    

    然后将文件中的open替换smart_open,原因:

    好像smart_open把函数名从open改成smart_open

    【讨论】:

    • 您似乎说过我们应该将一行更改为 . . .一条 100% 相同的线。
    【解决方案4】:

    在 C:\ProgramData\Anaconda3\lib\site-packages\gensim\utils.py 中,我只是将 from smart_open import open 更改为 from smart_open import smart_open 并且它起作用了。

    【讨论】:

      【解决方案5】:

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

      conda update smart_open

      pip install --upgrade smart_open

      【讨论】:

        【解决方案6】:
        \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和升级之后。

        【讨论】:

          【解决方案7】:

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

          conda install smart_open==2.0.0

          pip install smart_open==2.0.0.

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2021-02-27
            • 2021-12-04
            • 2021-05-30
            • 2021-11-07
            • 2021-03-07
            • 2021-04-27
            • 2021-05-27
            相关资源
            最近更新 更多