问题
I made a (one file) scrip in python for my client, the program is a success and now it needs to be distributed to 12 of my client employees.
The script I made uses a lot of libraries (imports), some of then are not popular at all so here goes the question:
Is there a way to distribute my program already compiled in bytecode? So the users can run it by just simply doing "python myProgram.pyc" or just "myProgram.pyc" (if it has +x property), I know this is entirely possible in Java by compiling the libraries inside a JAR file, is there anything similar for python?
Please don't recommend me py2exe since is far away for what I want, either other similar tools, I just want to distribute a package with all the necessary libraries already pre-compiled in bytecode so the final users don't need to worry about installing libs, pip, github, custom stuff, or anything. Hope you can help me, if not I will have to port the whole project to Java.
回答1:
If your client employees machine are Windows go for py2exe http://py2exe.org/
If Mac go for py2app https://pypi.python.org/pypi/py2app/
cx_Freeze http://cx-freeze.sourceforge.net/ is cross-platform and it should spit out executable that would run on any OS with Python installed.
PyInstaller http://www.pyinstaller.org/ is a good one too.
However, these methods do not compile and hence improve run-time performance improvements. Rather a way to distribute your script as a single executable with all the necessary modules.
You could use the compiled .pyc file with a wrapper around it for execution and package it as a single executable. However, performance improvements of doing so is debatable.
EDIT: It's been long though, recently started with cython and it could be a plausible solution for this problem. If not all, defining the variable types should do that is asked in the question.
来源:https://stackoverflow.com/questions/36026419/distribute-a-python-script-in-bytecode-precompiled-all-necessary-libraries