问题描述
有没有办法将python脚本编译成二进制?我有一个文件 python 脚本,它使用了很多模块.我想要的是在其他机器(freebsd)上拥有它的副本,但无需在每台主机上安装所有需要的模块.
Is there any way to compile python script into binary? I have one file python script which uses a lot of modules. What I would like is to have its copy on other machines (freebsd) but without installing all needed modules on every host.
在这种情况下有什么可能的解决方案?
What are possible solutions in such cases?
推荐答案
可以做你要求的程序有:
Programs that can do what you ask for are:
- PyInstaller:http://www.pyinstaller.org/ [Windows、Linux、OS X]
- cx_freeze:http://cx-freeze.sourceforge.net/ [Windows, Linux]
- py2exe:http://www.py2exe.org/ [Windows]
- py2app:http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html [os x]
- PyInstaller: http://www.pyinstaller.org/ [Windows, Linux, OS X]
- cx_freeze: http://cx-freeze.sourceforge.net/ [Windows, Linux]
- py2exe: http://www.py2exe.org/ [Windows]
- py2app: http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html [os x]
但如前所述,您也可以使用 Distribute 创建一个包,并将其他包作为依赖项.然后你可以使用 pip
来安装那个包,它会安装所有的包.不过,您仍然需要安装 Python 和 pip.
But as mentioned you can also create a Package with Distribute and have the other packages as dependencies. You can then uses pip
to install that package, and it will install all of the packages. You still need to install Python and pip, though.
这篇关于如何使我的 python 脚本易于移植?或者如何编译成具有所有模块依赖项的二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!