我打算将我的大型 python 程序打包成一个文件;
我的要求是:
- 只需下载 1 个文件
- 文件可以校验和
- 理想情况下,文件包含一些版本信息
- 使用系统python
到目前为止,包格式的最佳候选者是 .egg 和 .zip。
鸡蛋和拉链之间有什么实际区别?
我打算做什么:
嵌入式系统下载我的代码,例如package.zip
;它启动我的代码,例如python2 package.zip
我的代码可以验证自己,例如md5sum sys.argv[0]
。在我的服务器上报告和监控校验和。
Zipfiles are a bit magical, in that the built-in import will automagically import them. I've never tried importing an egg directly, so I don't know if that will or will not work.
The big boon you get from using eggs is that you can specify dependencies for your package. This may not be a big deal for you. With eggs you setup the requirements, publish to the pypi (if you want), and you've made your users life easier.
Once things are packaged up, pip (http://pypi.python.org/pypi/pip) makes dealing with your package easier. Here are examples of this ripped directly from the pip page -
$ pip install simplejson
$ pip install --upgrade simplejson
$ pip uninstall simplejson
You get a lot of bang from a little work. If you don't want to push your things up to the pypi, you can publish it on your own secret Pypi (read webserver), and specify that pip use a different URL for finding packages.
$ pip install -i http://mycoolserver.com/pypi
I'm no PIP expert, but with easy install (pip's predecessor) you could create your own PYPI pretty easy with Apache. Just publish the pypi directory, and allow it to show indexes (I think thats the right terminology), so that you can browse the file system for the pypi. With this setup, create a directory named after your package and drop your eggs in there. It "just works" (well for me :-))
鸡蛋是一个 zip 文件。
无论您使用哪种方法打包文件,您都可以在文件上使用 md5sum(或任何其他哈希函数) - 他们不关心文件的扩展名,只是二进制内容是相同的。
编辑:我在你澄清你的需求之前写了这个。这似乎不合适,因为它不使用系统 python 可执行文件。
您的问题标题向我表明您想为普通(即非pythonista)Windows最终用户打包它,以便他们只需双击即可运行它。Py2exe正是为此目的。
我采用这个假设是因为大多数 linux 用户都希望它是一个带有 setup.py 文件的存档,而不是一个可执行文件。至于 Mac OS X,我真的不知道。