簡體   English   中英

即使我剛剛安裝了 pyemd,也出現安裝錯誤

[英]Getting an error to install pyemd even though I just installed it

這是代碼:

from pyemd import emd

print("sentence 1:")
print(input_document_lower[0])
print("sentence 2:")
print(input_document_lower[1])
print("similarity:")
model_w2v.wmdistance(input_document_lower[0], input_document_lower[1])

這是錯誤:

sentence 1:
incorrect batch number printed primary label pbn
sentence 2:
unconfirmed oos met vial washing qualification sample per 
similarity:

ImportErrorTraceback (most recent call last)
<ipython-input-201-50af089a2354> in <module>()
      4 print(input_document_lower[1])
      5 print("similarity:")
----> 6 model_w2v.wmdistance(input_document_lower[0], input_document_lower[1])

C:\ProgramData\Anaconda2\lib\site-packages\gensim\models\word2vec.pyc in wmdistance(self, document1, document2)
   1308         Refer to the documentation for `gensim.models.KeyedVectors.wmdistance`
   1309         """
-> 1310         return self.wv.wmdistance(document1, document2)
   1311 
   1312     def most_similar_cosmul(self, positive=None, negative=None, topn=10):

C:\ProgramData\Anaconda2\lib\site-packages\gensim\models\keyedvectors.pyc in wmdistance(self, document1, document2)
    386 
    387         if not PYEMD_EXT:
--> 388             raise ImportError("Please install pyemd Python package to compute WMD.")
    389 
    390         # Remove out-of-vocabulary words.

ImportError: Please install pyemd Python package to compute WMD.

它安裝正確,所以我真的不知道出了什么問題。 大家有遇到過這種情況嗎?

我有同樣的錯誤,對我來說,解決方案是交換:

from gensim.similarities import WmdSimilarity
from pyemd import emd

進入

from pyemd import emd
from gensim.similarities import WmdSimilarity

不要問我為什么有效。

解決這個問題如下 -

如果您的pip install 不起作用,請使用此命令使用conda install 代替

conda install -c conda-forge pyemd

相信現在你已經成功安裝了pyemd。 現在,即使在成功導入后仍然出現錯誤時,請執行以下操作 - 在任何gensim module之前導入pyemd 我的意思是 pyemd 應該在上面。

from pyemd import emd
from gensim.similarities import WmdSimilarity
from gensim.models.doc2vec import LabeledSentence
from gensim.models.doc2vec import TaggedLineDocument

我希望你已經解決了這個問題:)

我遇到了一些問題,我在我的虛擬環境中安裝了這個包,但它不起作用。 然后我重新啟動了我的電腦,然后它就可以工作了。

添加如下所示的行

global PYEMD_EXT

就在 try:except 代碼塊上方

try:
    from pyemd import emd
    PYEMD_EXT = True
except ImportError:
    PYEMD_EXT = False

轉到 keyedvectors.py 文件並刪除 try catch 塊。

這:

  try:
        from pyemd import emd
        PYEMD_EXT = True
    except ImportError:
        PYEMD_EXT = False

去除導入錯誤提示

if not PYEMD_EXT:
            raise ImportError("Please install pyemd Python package to compute WMD.")

添加這個

from pyemd import emd

要了解有關錯誤檢查的更多信息,請訪問 https://github.com/RaRe-Technologies/gensim/pull/2229/files

即使在此代碼拋出錯誤之后。 一個可能的問題是你將在 jupyter 中運行,所以重新啟動整個 karnel 就行了!!!

在 Mac 和 Linux 上, pip install pyemd工作正常。

但是,在 Windows 上,您可能會在安裝時遇到問題。

出現此錯誤是由於

pyemd 在構建期間需要一些 C++ 依賴項。

這可以通過安裝Build Tools for Visual Studio 2019Build Tools for Visual Studio 2019來解決,如下所示:

查看 wmdistance 方法的文檔

警告 -------- 此方法僅在安裝了pyemd <https://pypi.org/project/pyemd/> _ 時有效。

If one of the documents have no words that exist in the vocab, `float('inf')` (i.e. infinity)
will be returned.

Raises
------
ImportError
    If `pyemd <https://pypi.org/project/pyemd/>`_  isn't installed.

所以在使用wmdistance安裝包pyemd之前

pip 安裝 pyemd

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM