wangtingc 2018-01-25 09:11 采纳率: 0%
浏览 1198
已结题

error LNK1104: cannot open word2vec_inner.pyd'

windons实现Yang Liu的Topical Word Embeddings时,运行错误
TWE\test.py:

import gensim
sentence_word = gensim.models.word2vec.LineSentence("tmp/word.file")

TWE\gensim\models\word2vec.py:

try:
    raise ImportError  # ignore for now
    from gensim_addons.models.word2vec_inner import train_sentence_sg, train_sentence_cbow, FAST_VERSION, train_sentence_topic
except ImportError:
    try:
        # try to compile and use the faster cython version
        import pyximport
        print 'import pyximport'
        models_dir = os.path.dirname(__file__) or os.getcwd()
        print 'models_dir'
        pyximport.install(setup_args={"include_dirs": [models_dir, get_include()]})
        print 'pyximport'   # is the follow code's problem
        from word2vec_inner import train_sentence_sg, train_sentence_cbow, FAST_VERSION, train_sentence_topic
        print 'from word2vec'
    except:
        print 'except2'
        # failed... fall back to plain numpy (20-80x slower training than the above)
        FAST_VERSION = -1

        def train_sentence_sg(model, sentence, alpha, work=None):
                                                          ...
                def train_sentence_cbow(model, sentence, alpha, work=None, neu1=None):
                                                           ...
class Word2Vec(utils.SaveLoad):
    def __init__(self, sentences=None, size=100, alpha=0.025, window=5, min_count=5,sample=0, seed=1, workers=1, min_alpha=0.0001, sg=1, hs=1, negative=0, cbow_mean=0):
                                                          ...
    def train(self, sentences, total_words=None, word_count=0, chunksize=100):
                if FAST_VERSION < 0:
                        import warnings
            warnings.warn("Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`")
            logger.info("training model with %i workers on %i vocabulary and %i features, "
             "using 'skipgram'=%s 'hierarchical softmax'=%s 'subsample'=%s and 'negative sampling'=%s" %
              (self.workers, len(self.vocab), self.layer1_size, self.sg, self.hs, self.sample, self.negative))
                                                                   ...
        def worker_train():
                        if self.sg:
                job_words = sum(train_sentence_topic(self, sentence, alpha, work) for sentence in job)
            else:
                job_words = sum(train_sentence_cbow(self, sentence, alpha, work, neu1) for sentence in job)
                                                                          ...

运行train.py,出现以下错误:

E:\Python27\python.exe D:/pycharm/TWE/TWE1/train.py wordmap.txt model-final.tassign 100
import pyximport
models_dir
pyximport
word2vec_inner.c
e:\python27\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(12) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
C:\Users\hp\.pyxbld\temp.win32-2.7\Release\pyrex\gensim\models\word2vec_inner.c(15079) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
C:\Users\hp\.pyxbld\temp.win32-2.7\Release\pyrex\gensim\models\word2vec_inner.c(15085) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
LINK : fatal error LNK1104: cannot open file 'C:\Users\hp\.pyxbld\lib.win32-2.7\gensim\models\word2vec_inner.pyd'
except2
Training the word vector...
D:\pycharm\TWE\TWE1\gensim\models\word2vec.py:410: UserWarning: Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`
warnings.warn("Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`")
PROGRESS: at 100.00% words, alpha 0.02500, 2556 words/s
Training the topic vector...
D:\pycharm\TWE\TWE1\gensim\models\word2vec.py:882: UserWarning: Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`
warnings.warn("Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`")
Exception in thread Thread-23:
Traceback (most recent call last):
File "E:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "E:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
File "D:\pycharm\TWE\TWE1\gensim\models\word2vec.py", line 909, in worker_train
job_words = sum(train_sentence_topic(self, sentence, alpha, work) for sentence in job)
File "D:\pycharm\TWE\TWE1\gensim\models\word2vec.py", line 909, in <genexpr>
job_words = sum(train_sentence_topic(self, sentence, alpha, work) for sentence in job)
NameError: global name 'train_sentence_topic' is not defined

Saving the topic vectors...
Saving the word vectors...

Process finished with exit code 0

我已经安装了Microsoft Visual C++ Compiler for Python 2.7和cython,而且我也用一个小的程序测试了cython是正确编译和安装了的,但是还是出现问题。按照这个博客上的测试了cython,然后按照一个博客运行的TWE程序。看了好久,总结了应该是在word2vec.py最开始导入不了train_sentence_sg, train_sentence_cbow, FAST_VERSION, train_sentence_to。但是为什么导入不了,总觉得不应该,我成功编译了pyx文件的,cython也是正确安装了的。到底是什么问题,有大神遇到过这个问题的吗?求大神帮忙,谢谢!急急急,在线等

  • 写回答

1条回答

  • threenewbee 2018-01-25 13:52
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码