How to make my python script easy portable? or how to compile into binary with all module dependencies?(如何使我的 python 脚本易于移植?或者如何编译成具有所有模块依赖项的二进制文件?)
问题描述
有没有办法将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 脚本易于移植?或者如何编译成具有所有模块依赖项的二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使我的 python 脚本易于移植?或者如何编译成
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
