問題描述
有沒有辦法將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 腳本易于移植?或者如何編譯成具有所有模塊依賴項的二進制文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!