我在64位Windows机器上使用Anacondas。Cython Hello World示例适用于Anacondas Python 3.3,但不适用于3.4
我编译了一个hello world Cython的例子。它是在文件hello.pyx,并包含:
def say_hello_to(name):
print("Hello %s!" % name)
我使用run_hello.py
import pyximport; pyximport.install()
import hello as hello
hello.say_hello_to('jon')
安装文件是setup.py运行它:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'Hello world app',
ext_modules = cythonize("hello.pyx"),
)
我然后使用以下代码在Anacondas上编译Python 3.3中的代码:
> activate py33
> python setup.py build_ext --inplace
(请注意,py33是我的Python 3.3环境)
我可以运行的例子: “你好!乔恩”
python run_hello.py
打印出如预期。
现在,如果我在我的环境改变到Python 3.4和编译:
> activate py34
> python setup.py build_ext --inplace
我没有得到任何错误,并且外壳显示
running build_ext
但是,如果我尝试从运行run_hello.py在PY34环境:
python run_hello.py
我得到:
Traceback (most recent call last):
File "run_hello.py", line 2, in <module>
import hello as hello
ImportError: DLL load failed: The specified module could not be found.
该错误不是很具描述性。我能做些什么来帮助我在Python 3.4上完成这项工作?
如果我删除的hello.c从我的硬盘驱动器/生成文件夹,试图从Python来编译3.4回报:
Compiling hello.pyx because it changed.
Cythonizing hello.pyx
running build_ext
building 'hello' extension
creating build
creating build\temp.win-amd64-3.4
creating build\temp.win-amd64-3.4\Release
C:\Anaconda\envs\py34\Scripts\gcc.bat -mdll -O -Wall -IC:\Anaconda\envs\py34\include -IC:\Anaconda\envs\py34\include -c hello.c -o build\temp.win-amd64-3.4\Release\hello.o
writing build\temp.win-amd64-3.4\Release\hello.def
C:\Anaconda\envs\py34\Scripts\gcc.bat -shared -s build\temp.win-amd64-3.4\Release\hello.o build\temp.win-amd64-3.4\Release\hello.def -LC:\Anaconda\envs\py34\libs -LC:\Anaconda\envs\py34\PCbuild\amd64
-lpython34 -lmsvcr100 -o c:\Users\Jon\Documents\GitHub\CythonFunctions\example1\hello.pyd
build\temp.win-amd64-3.4\Release\hello.o:hello.c:(.text+0x314): undefined reference to `__imp__PyThreadState_Current'
build\temp.win-amd64-3.4\Release\hello.o:hello.c:(.text+0x493): undefined reference to `__imp__Py_NoneStruct'
build\temp.win-amd64-3.4\Release\hello.o:hello.c:(.text+0x97b): undefined reference to `__imp_PyExc_ImportError'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\Anaconda\\envs\\py34\\Scripts\\gcc.bat' failed with exit status 1
如果我与Python 3.3一样,我得到:
Compiling hello.pyx because it changed.
Cythonizing hello.pyx
running build_ext
building 'hello' extension
creating build
creating build\temp.win-amd64-3.3
creating build\temp.win-amd64-3.3\Release
C:\Anaconda\envs\py33\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\envs\py33\include -IC:\Anaconda\envs\py33\include -c hello.c -o build\temp.win-amd64-3.3\Release\hello.o
writing build\temp.win-amd64-3.3\Release\hello.def
C:\Anaconda\envs\py33\Scripts\gcc.bat -DMS_WIN64 -shared -s build\temp.win-amd64-3.3\Release\hello.o build\temp.win-amd64-3.3\Release\hello.def -LC:\Anaconda\envs\py33\libs -LC:\Anaconda\envs\py33\PCb
uild\amd64 -lpython33 -lmsvcr100 -o c:\Users\Jon\Documents\GitHub\CythonFunctions\example1\hello.pyd
谁遇到一些其他用户“gcc.bat失败,退出状态1”已发现的问题是由于32/64位冲突。
在py33版本的编译数据中,gcc.bat参数中有-DMS_WIN64,但它不在py34参数中。那可能是导致我的问题的原因吗?如果是这样,我怎么得到py34来添加它?
谢谢,但py33和py34都使用-lmsvcr100选项。 – Ginger 2015-04-01 07:39:13
哦,对不起,我没有在3.4输出中看到它。是否删除libpython修复它? – asmeurer 2015-04-01 18:27:16
我尝试删除它,但它似乎并未安装在我的py34环境中。 – Ginger 2015-04-02 18:56:27