如何分发 python 程序? [英] How can I distribute python programs?

查看:43
本文介绍了如何分发 python 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序如下所示:

<前>主文件视窗/__init__.py主窗口.py...模型/__init__.py订单.py...资源/图像1.png标志.jpg...

程序以 main.py 启动.有没有一种好方法可以从中创建最终"应用程序?我正在考虑像 py2exe/py2app 这样的东西,但没有将 python 解释器/模块复制到只有一个可执行文件的应用程序中.

我查看了 distutils,但这看起来像是将程序安装到 Python 目录中,这在非 Linux 平台上并不常见.

目前我只是将整个源文件夹复制到目标机器上,并在 Windows 上为 main.pyw 创建一个别名.一些不便:

  • 该图标是默认的 Python 图标.
  • 我必须手动创建别名.
  • 在我的源目录中有很多附加文件,例如源控制文件夹.
  • 我必须手动将 main.py 重命名为 main.pyw.
  • 如果目标机器上只有 `.pyo* 文件就好了.没有真正的原因,我只是不喜欢有不必要的文件.

如何创建一个好的自动化分发?

  • 对于窗户?(这是我目前必须支持的唯一平台.)
  • Mac 版?
  • Linux?

解决方案

分发 Python 应用程序的正常方式是使用 distutils.它既用于分发库类型的 python 模块,也用于 python 应用程序,尽管我不知道它在 Windows 上是如何工作的.无论如何,如果您使用 distutils,您将必须在 Windows 上单独安装 Python.

我可能会建议您使用适用于 Linux 的 disutils 和 Py2exe 或适用于 Windows 的类似工具分发它.对于 OS X,我不知道.如果它是最终用户应用程序,您可能需要磁盘映像类型的东西,我不知道该怎么做.但是请阅读这篇文章,了解有关它的用户体验的更多信息.对于为程序员制作的应用程序,您可能也可以在 OS X 上安装 distutils 类型.

My application looks like this:

main.py
windows/
    __init__.py
    mainwindow.py
    ...
model/
    __init__.py
    orders.py
    ...
resources/
    image1.png
    logo.jpg
    ...

The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinking of something like py2exe/py2app, but without copying the python interpreter / modules into the application where one has only one executable.

I had a look at distutils, but this looks like it installs a program into the Python directory, which isn't usual on non-linux platforms.

At the moment I just copy the whole source folder onto the target machine and create an alias to main.pyw on windows. Some inconveniences:

  • The icon is the default python icon.
  • I have to create the alias manually.
  • In my source directory there are a lot of additional files like the source control folder.
  • I have to rename main.py to main.pyw manually.
  • It would be nice if only `.pyo* files are on the target machine. There's no real reason for it, I just don't like having unnecessary files.

How does one create a nice automated distribution?

  • for windows? (That's the only platform that I have to support at the moment.)
  • for mac?
  • for linux?

解决方案

The normal way of distributing Python applications is with distutils. It's made both for distributing library type python modules, and python applications, although I don't know how it works on Windows. You would on Windows have to install Python separately if you use distutils, in any case.

I'd probably recommend that you distribute it with disutils for Linux, and Py2exe or something similar for Windows. For OS X I don't know. If it's an end user application you would probably want an disk image type of thing, I don't know how to do that. But read this post for more information on the user experience of it. For an application made for programmers you are probably OK with a distutils type install on OS X too.

这篇关于如何分发 python 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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