分发嵌入的Cython编译的代码并使其可在任何计算机上运行所需的最少文件集 [英] Minimal set of files required to distribute an embed-Cython-compiled code and make it work on any machine

查看:85
本文介绍了分发嵌入的Cython编译的代码并使其可在任何计算机上运行所需的最少文件集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:如何使用Cython代替Py2exe,cx_freeze,pyinstaller等作为分发方法。






按照



问题:分发-嵌入-所需的最小文件集是多少?用Cython编译的代码是否可以在任何计算机上运行(以前没有安装Python)?


解决方案

经过进一步研究(我在空的Win 7 x64位VM中尝试,之前未安装任何VCredist),看来这些文件就足够了:



注意:



  • 如果您需要另一个库,例如 pygame ,只需从 C:\Python37复制/粘贴文件夹\lib\site-packages\pygame 似乎可以工作



  • 对我来说,conrt140.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.0\VC\vcvarsall.bat" x64
cl test.c /I C:\Python37\include /link C:\Python37\libs\python37.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:

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:

Notes:

  • if you require another library, like pygame, just copy/paste the folder from C:\Python37\Lib\site-packages\pygame seems to work

  • for me, concrt140.dll, msvcp140.dll, vccorlib140.dll did not seem necessary

这篇关于分发嵌入的Cython编译的代码并使其可在任何计算机上运行所需的最少文件集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆