在预编译的字节码+所有必需的库中分发python脚本 [英] Distribute a python script in bytecode precompiled + all necessary libraries

查看:120
本文介绍了在预编译的字节码+所有必需的库中分发python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中为客户制作了一个文件(脚本),该程序成功了,现在需要分发给我的12位客户雇员。

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:

有没有一种分发我的脚本的方法?程序已经用字节码编译了吗?因此,用户只需执行 python myProgram.pyc或 myProgram.pyc(如果具有+ x属性)就可以运行它,我知道在Java中通过编译JAR文件中的库是完全可能的,

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?

请不要推荐我py2exe,因为它与我想要的东西相去甚远,或者其他类似的工具,我只想分发包含所有必需的库都已经以字节码预编译,因此最终用户无需担心安装库,pip,github,自定义内容或其他任何东西。希望您能为我提供帮助,否则我将不得不将整个项目移植到Java。

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.

推荐答案

如果您的客户员工计算机是Windows使用py2exe http://py2exe.org/

If your client employees machine are Windows go for py2exe http://py2exe.org/

如果Mac使用py2app https://pypi.python.org/pypi/py2app/

If Mac go for py2app https://pypi.python.org/pypi/py2app/

cx_Freeze http:// cx-freeze .sourceforge.net / 是跨平台的,应该吐出可在安装了Python的任何操作系统上运行的可执行文件。

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/ 也是不错的选择。

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.

您可以使用已编译的.pyc文件及其周围的包装器来执行并将其打包作为单个可执行文件。但是,这样做的性能改进值得商.。

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.

编辑:
尽管很久了,最近才从cython开始,它可以可能是解决这个问题的方法。如果不是全部,那么定义变量类型应该可以解决问题。

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.

这篇关于在预编译的字节码+所有必需的库中分发python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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