分发嵌入 Cython 编译的代码并使其在任何机器上工作所需的最少文件集 [英] Minimal set of files required to distribute an embed-Cython-compiled code and make it work on any machine
问题描述
TL;DR:如何使用 Cython 作为分发方法而不是 Py2exe、cx_freeze、pyinstaller 等
<小时>在
问题:分发 --embed
-Cython 编译的代码并使其在任何机器上运行(之前没有安装 Python)所需的最小文件集是什么?
经过进一步研究(我在一个空的 Win 7 x64 位 VM 中尝试过,之前没有安装任何 VCredist),似乎这些文件就足够了:
程序本身,
test.exe
(由cython --embed
生成,并用cl.exe
编译)>python37.dll
python37.zip
来自 的包.org/downloads/windows/" rel="noreferrer">https://www.python.org/downloads/windows/vcruntime140.dll
,如 我可以将 Visual Studio 2015 C++ Redistributable DLL 与我的应用程序捆绑在一起吗? 或要求用户安装 vc_redist.x64.exe 之前ucrtbase.dll
还需要30多个文件
<块引用>api-ms-win-*.dll
;如果不是,您将出现以下错误:... api-ms-win-crt-runtime-l1-1-0.dll 丢失...
注意事项:
如果你需要另一个库,比如
pygame
,只需从C:Python37Libsite-packagespygame
复制/粘贴文件夹似乎工作对我来说,concrt140.dll、msvcp140.dll、vccorlib140.dll 似乎没有必要
TL;DR: how to use Cython as a distribution method instead of Py2exe, cx_freeze, pyinstaller, etc.
Following Making an executable in Cython, I'd like to see how it could be possible to distribute a Python program to any Windows user (who doesn't have Python already installed on his machine) by compiling it first with Cython --embed
.
Let's use a test.py
:
import json
print(json.dumps({'key': 'hello world'}))
and compile it:
cython test.py --embed
call "C:Program Files (x86)Microsoft Visual Studio 14.0VCvcvarsall.bat" x64
cl test.c /I C:Python37include /link C:Python37libspython37.lib
It works and produces a 140KB test.exe
executable.
Running test.exe
on another machine doesn't work out-of-the-box, it requires:
- python37.dll in the same folder
- to install the usual vc_redist.x64.exe file
Even with this, it still does not work (screenshot below instead of copy/paste because I didn't manage the copy/paste in the VM - off topic here):
ModuleNotFoundError: No module named 'encodings'
Question: what is the minimal set of files required to distribute an --embed
-Cython-compiled code and make it work on any machine (without Python previously installed on it)?
After further research (I tried in an empty Win 7 x64 bit VM, without any VCredist previously installed), it seems that these files are enough:
the program itself,
test.exe
(produced bycython --embed
and compilation withcl.exe
)python37.dll
python37.zip
coming from packages named "Windows x86-64 embeddable zip file" in https://www.python.org/downloads/windows/vcruntime140.dll
, as mentioned in Can I bundle the Visual Studio 2015 C++ Redistributable DLL's with my application? or ask the user to install vc_redist.x64.exe beforeucrtbase.dll
more than 30 files
api-ms-win-*.dll
were required too; if not you will have the following error:... api-ms-win-crt-runtime-l1-1-0.dll is missing ...
Notes:
if you require another library, like
pygame
, just copy/paste the folder fromC:Python37Libsite-packagespygame
seems to workfor me, concrt140.dll, msvcp140.dll, vccorlib140.dll did not seem necessary
这篇关于分发嵌入 Cython 编译的代码并使其在任何机器上工作所需的最少文件集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!