Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

python - Minimal set of files required to distribute an embed-Cython-compiled code and make it work on any machine

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:

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'

enter image description here

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:Python37Libsite-packagespygame seems to work

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...