0

安装程序.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
extensions = [
    Extension("word2vec_inner", ["word2vec_inner.pyx"],
          include_dirs=[numpy.get_include()])
    ]
setup(
    name="word2vec_inner",
    ext_modules=cythonize(extensions),
)

错误:

Warning: Extension name 'word2vec_inner' does not match fully qualified name
'TWE-1.gensim.models.word2vec_inner' of 'word2vec_inner.pyx'
Compiling word2vec_inner.pyx because it changed.
[1/1] Cythonizing word2vec_inner.pyx

Error compiling Cython file:
------------------------------------------------------------
...
#!/usr/bin/env cython
^
------------------------------------------------------------

word2vec_inner.pyx:1:0: 'TWE-1.gensim.models.word2vec_inner' is not a valid 
module name
Traceback (most recent call last):
  File "D:\PyCharm 2017.3\helpers\pydev\pydevd.py", line 1668, in <module>
    main()
  File "D:\PyCharm 2017.3\helpers\pydev\pydevd.py", line 1662, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "D:\PyCharm 2017.3\helpers\pydev\pydevd.py", line 1072, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:/pycharm/TWE/TWE-1/gensim/models/setup.py", line 11, in <module>
    ext_modules=cythonize(extensions),
  File "E:\Python27\lib\site-packages\cython-0.27.3-py2.7-
win32.egg\Cython\Build\Dependencies.py", line 1039, in cythonize
    cythonize_one(*args)
  File "E:\Python27\lib\site-packages\cython-0.27.3-py2.7-
win32.egg\Cython\Build\Dependencies.py", line 1161, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: word2vec_inner.pyx

我已经为 Python 2.7 和 cython 安装了 Microsoft Visual C++ 编译器,但它无法编译。总是出现这个问题。如何解决这个问题呢?非常感谢!

4

1 回答 1

0

我找到了解决Cython 编译错误“不是有效的模块名称”的方法 ,它是文件夹名称中的破折号。我现在已重命名该文件夹。但我不知道为什么。

于 2018-01-22T03:00:29.550 回答