Cython编译为exe,Windows [英] Cython compile to exe, Windows
问题描述
我无法在Windows上将Cython生成的C代码编译为EXE。
Windows 10
Python 3.5,32位,Anaconda
Visual Studio 14.0
Python C:\Anaconda3\Scripts\cython-script.py test.py --embed
我试着将 test.c 编译为 test.exe 使用命令行:
C:\Program Files(x86)\ Microsoft Visual Studio 14.0 \VC \vcvarsall .bat x86
#(未显示)cd到test.c目录
cl.exe / nologo / Ox / MD / W3 / GS- / DNDEBUG -Ic:\Anaconda3\include -Ic: \Anaconda3\PC /Tctest.c / link /OUT:\"test.exe/ SUBSYSTEM:CONSOLE / MACHINE:X86 / LIBPATH:c:\Anaconda3\Lib\site-packages\Cython\Includes \libc / LIBPATH:c:\Anaconda3\Lib\site-packages\Cython\Includes\PCbuild
但结果是错误消息:
LINK:致命错误LNK1104:无法打开文件'python35 .lib'
我不知道是什么原因导致这个错误,我也不相信我指向正确的LIBPATH。
我没有找到解决Windows + Cython + Anaconda + Python 3.5 + C编译问题的线程。非常感谢您的帮助。
编辑:
cjrh的回答下面解决了初始错误和test.c成功编译为test.exe。
但是,运行test.exe会产生以下错误:
致命的Python错误:Py_Initialize:无法加载文件系统编解码器
LookupError:没有编码解码器搜索功能注册:找不到编码
修复:创建一个名为PYTHONPATH的新系统变量。在Windows中,可以通过以下方式完成:
我的电脑>属性>高级>环境变量。
使PYTHONPATH包含以下错误: br /> C:\Anaconda3; C:\Anaconda3\DLLs; C:Anaconda3 \Lib; C:Anaconda3 \Scripts
解决方案我没有Windows实例方便,但它看起来像你可能会缺少链接Python库本身的 LIBPATH
条目, / p>
... / LIBPATH:c:\Anaconda3\libs / LIBPATH:c:\Anaconda3\PCbuild
I'm having trouble compiling Cython generated C code to an EXE on Windows.
Windows 10
Python 3.5, 32bit, Anaconda
Visual Studio 14.0
Using this stackoverflow thread, I was able to convert test.py to test.c using the command line:
Python C:\Anaconda3\Scripts\cython-script.py test.py --embed
I tried compiling test.c to test.exe again using the command line:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat x86
# (not shown) cd to test.c directory
cl.exe /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ic:\Anaconda3\include -Ic:\Anaconda3\PC /Tctest.c /link /OUT:"test.exe" /SUBSYSTEM:CONSOLE /MACHINE:X86 /LIBPATH:c:\Anaconda3\Lib\site-packages\Cython\Includes\libc /LIBPATH:c:\Anaconda3\Lib\site-packages\Cython\Includes\PCbuild
But the result is an error message:
LINK : fatal error LNK1104: cannot open file 'python35.lib'
I'm not sure what's causing this error, and I'm also not confident that I am pointing to the correct LIBPATH.
I haven't found a thread that solved the issue of Windows + Cython + Anaconda + Python 3.5 + C Compilation. Thanks for any help.
EDIT:
cjrh's answer below solved the initial error and the test.c successfully compiled to test.exe.
however, running test.exe produced the following error:
Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding
The fix: create a new system variable called PYTHONPATH. In Windows, this is can be done by:
My Computer > Properties > Advanced > Environment Variables.
Making PYTHONPATH include the below fixed the error:
C:\Anaconda3;C:\Anaconda3\DLLs;C:Anaconda3\Lib;C:Anaconda3\Scripts
解决方案 I don't have a Windows instance handy, but it looks like you may be missing the LIBPATH
entries for linking the Python library itself, something like
... /LIBPATH:c:\Anaconda3\libs /LIBPATH:c:\Anaconda3\PCbuild
这篇关于Cython编译为exe,Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!