【问题标题】:Cython compile to exe, WindowsCython 编译为 exe,Windows
【发布时间】:2016-04-02 01:19:20
【问题描述】:

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

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

使用this stackoverflow 线程,我能够使用命令行将 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
# (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

但结果是错误信息:

LINK : fatal error LNK1104: cannot open file 'python35.lib'

我不确定是什么导致了这个错误,我也不确定我指向的是正确的 LIBPATH。

我还没有找到解决 Windows + Cython + Anaconda + Python 3.5 + C 编译问题的线程。感谢您的帮助。

编辑:

下面cjrh的回答解决了最初的错误,test.c成功编译为test.exe。

但是,运行 test.exe 产生了以下错误:

Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding

修复:创建一个名为 PYTHONPATH 的新系统变量。在 Windows 中,这可以通过以下方式完成:

我的电脑 > 属性 > 高级 > 环境变量。

使 PYTHONPATH 包含以下修复错误:

C:\ Anaconda3;C:\Anaconda3\DLLs;C:Anaconda3\Lib;C:Anaconda3\Scripts

【问题讨论】:

    标签: python windows compilation cython anaconda


    【解决方案1】:

    我手边没有 Windows 实例,但看起来您可能缺少用于链接 Python 库本身的 LIBPATH 条目,例如

    ... /LIBPATH:c:\Anaconda3\libs /LIBPATH:c:\Anaconda3\PCbuild
    

    【讨论】:

      猜你喜欢
      • 2011-02-04
      • 1970-01-01
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 2012-05-15
      相关资源
      最近更新 更多