Cython编译为exe,Windows

编程入门 行业动态 更新时间:2024-10-21 12:54:22
本文介绍了Cython编译为exe,Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法在Windows上将Cython生成的C代码编译为EXE。

Windows 10 Python 3.5,32位,Anaconda Visual Studio 14.0

使用 test.py 转换为 test.c :

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

本文发布于:2023-11-05 08:18:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:译为   Cython   Windows   exe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!