我目前正在开发一个从gensim调用Word2Vec类的项目。我已经通过以下方式下载了gensim:
pip install -U gensim
如果我打开python shell并输入:
from gensim.models import Word2Vec
我收到以下错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Library/Python/2.7/site-packages/gensim/__init__.py", line 6, in <module>
from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Library/Python/2.7/site-packages/gensim/models/__init__.py", line 13, in <module>
from .word2vec import Word2Vec
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Library/Python/2.7/site-packages/gensim/models/word2vec.py", line 100, in <module>
from gensim.models.word2vec_inner import train_sentence_sg, train_sentence_cbow, FAST_VERSION,\
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "__init__.pxd", line 155, in init gensim.models.word2vec_inner (./gensim/models/word2vec_inner.c:9234)
ValueError: numpy.dtype has the wrong size, try recompiling
卸载并重新安装许多scipy,numpy和gensim变体后。根据我之前阅读的有关上述错误的内容使用以下命令后:
pip uninstall numpy
pip uninstall pandas
pip install pandas
easy_install --upgrade numpy
pip install -U gensim
现在我得到了一个不同的错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Library/Python/2.7/site-packages/gensim/__init__.py", line 6, in <module>
from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Library/Python/2.7/site-packages/gensim/models/__init__.py", line 13, in <module>
from .word2vec import Word2Vec
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Library/Python/2.7/site-packages/gensim/models/word2vec.py", line 92, in <module>
from gensim import utils, matutils # utility fnc for pickling, common scipy operations etc
ImportError: cannot import name utils
如果我输入:
from gensim import utils
我得到与上面相同的错误。由于某种原因,没有从gensim正确导入utils但我不知道为什么会发生这种情况。我对python来说相当新,这对我来说相当混乱,但是在我之前的所有安装之后我注意到了一个BIG FIX!
如果我打电话:
from gensim import utils
当我在终端中调用python2.7时,导致utils错误不会发生。但是当我在pycharm中使用python解释器时(以下版本):
2.7.10 (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7)
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
错误仍然存在。
当我在终端中调用pycharm时,它从以下库中调用python:
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
我不知道python中的python shell与终端python shell是否不同但我不知道为什么一个shell工作正常但另一个shell会导致import utils错误。任何帮助将不胜感激!