简体   繁体   English

在Mac中导入gensim

[英]importing gensim in mac

I'm having a problem when trying to import gensim in python. 尝试在python中导入gensim时遇到问题。 When typing: 输入时:

import gensim 导入gensim

I got the following error: 我收到以下错误:

Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/gensim/ init .py", line 6, in from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization ImportError: cannot import name parsing 追溯(最近一次通话):文件“”,行1,在文件“ /Library/Python/2.7/site-packages/gensim/ init .py”中,行6,来自gensim导入解析,matutils,接口,语料库,模型,相似性,摘要ImportError:无法导入名称解析

Also, when I view " init .py" it contains only the following lines: 另外,当我查看“ init .py”时,它仅包含以下几行:

bring model classes directly into package namespace, to save some typing 将模型类直接带到包名称空间中,以节省一些输入

from .summarizer import summarize, summarize_corpus 从.summarizer导入摘要,summary_corpus

from .keywords import keywords 从.keywords导入关键字

Any idea on how to solve this problem is highly appreciated. 高度赞赏有关解决此问题的任何想法。

I'm using: MAC 10.10.5 and Python 2.7 我正在使用:MAC 10.10.5和Python 2.7

Thank you 谢谢

I had a similar error. 我有一个类似的错误。 I used pip to update itself, then uninstall, reinstall, and update gensim. 我使用pip进行自我更新,然后卸载,重新安装和更新gensim。 I also pip installed Theano (b/c mine was unable to import something related to it). 我还点安装了Theano(b / c mine无法导入与此相关的东西)。

pip install --upgrade pip
pip uninstall gensim
pip install --upgrade gensim 
pip install Theano 

Then I needed to close and restart a new terminal python shell, and it worked! 然后,我需要关闭并重新启动一个新的终端python shell,它起作用了!

One other note-- if you look at the error message, you can see the filepath to the .py files in the /gensim folder and the line in that .py file causing the error. 另一注-如果您查看错误消息,则可以看到/ gensim文件夹中.py文件的文件路径以及该.py文件中导致错误的行。 Then you can try to manually run each import that is causing an error (after cd-ing to the appropriate folder). 然后,您可以尝试手动运行每个导致错误的导入(将CD刻录到相应的文件夹之后)。 This might help you find what packages are causing the problem. 这可以帮助您找到导致问题的软件包。

The file "init.py" is trying to import things from gensim.py. 文件“ init.py”正在尝试从gensim.py导入内容。 It's unable to import one of the classes. 它无法导入其中一个类。 As you can see in the last line of your error, it says it was unable to import name parsing. 正如您在错误的最后一行中看到的那样,它表示无法导入名称解析。 I suggest: -if you downloaded the package from the internet(I'm quite new to python, and still don't know all the downloadable content): -Search the website for what this package means and try redownloading it (re-install the module). 我建议:-如果您从互联网上下载了该软件包(我对python还是很陌生,但仍然不知道所有可下载的内容):-在网站上搜索此软件包的含义,然后尝试重新下载(重新安装)模块)。 Also, try looking after if the versions are compatible. 另外,请尝试检查版本是否兼容。 If this package have many versions, find the appropriate version according to your python version. 如果此软件包有很多版本,请根据您的python版本找到合适的版本。

What happens is that part of the package is missing. 发生的情况是该包装的一部分丢失了。

我通过使用virtualenv在虚拟环境中重新安装该库解决了该问题,如下所述: http : //docs.python-guide.org/en/latest/dev/virtualenvs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM