Cython compile to exe, Windows

回眸只為那壹抹淺笑 提交于 2019-12-11 13:53:04

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/34489324/cython-compile-to-exe-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!