【问题标题】:import gensim and got an TypeError: expected bytes, Descriptor found导入 gensim 并得到一个 TypeError: expected bytes, Descriptor found
【发布时间】:2020-09-10 22:42:59
【问题描述】:

我尝试在 python3 中导入 gensim 库。 所有库都是最新版本。 在第一次导入中得到一个TypeError: expected bytes, Descriptor found 并在第二次导入时出现此错误:

 import gensim

> AttributeError                            Traceback (most recent call last)
<ipython-input-7-e70e92d32c6e> in <module>
----> 1 import gensim

~\Anaconda3\lib\site-packages\gensim\__init__.py in <module>
      3 """
      4 

~\Anaconda3\lib\site-packages\smart_open\transport.py in <module>
     20 NO_SCHEME = ''
     21 
---> 22 _REGISTRY = {NO_SCHEME: smart_open.local_file}
     23 
     24 

AttributeError: module 'smart_open' has no attribute 'local_file'

【问题讨论】:

  • 您使用什么命令安装gensim? (看起来您使用的是 Anaconda;您是如何设置工作环境的?​​如果您创建一个新环境并重试,是否会出现同样的错误?)
  • (另外,如果可以复制:生成原始TypeError 的确切事件序列和代码是什么,以及该错误的完整显示堆栈?)

标签: python import typeerror gensim attributeerror


【解决方案1】:

我通过以下步骤解决了这个问题:

pip install smart-open==1.9.0
pip install gensim==3.4.0

这对我有用

【讨论】:

  • 那些看起来不像是有效的pip 命令,通常包含单词install,并使用=-符号指定版本。 (并且,与gensim 相关的包和您的错误消息中的包是smart_open,而不是open-smart。另请注意,gensim-3.4.0 是一个超过 2 年的版本,没有最近的修复/功能。跨度>
  • @gojomo 我使用了 pip install gensim==3.8.3 和 pip install smart-open==2.0.0 但出错了。你知道gensim 3.8.3兼容哪个版本的smart-open吗?
  • 感谢您修复此答案以包含真实的pip 命令。但是,如果它没有解决您的问题,为什么将其发布为答案? (如果您仍然遇到与上述相同的错误,请删除此答案,改为改进问题,或回答 cmets 中的问题,以帮助解决原始错误。如果您遇到新错误,请说明步骤和新错误的确切细节/消息。)
猜你喜欢
  • 2021-06-05
  • 2021-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-29
  • 1970-01-01
  • 2021-04-27
相关资源
最近更新 更多