分发python应用教程 [英] Distributing python application tutorials

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

问题描述

您好,作为 Python 新手,我编写了一个小型的 Python 应用程序,可以将 excel 工作表转换为 sqlite 数据库表.它不是一个非常复杂的应用程序,但它确实使用了像 xlrd (http://pypi.python.org/pypi/xlrd) 这样的外部模块/包,我在编写我的应用程序时必须下载并安装它.现在一切都完成了,我想把它分发给我的朋友,所有 Windows 用户,虽然他们的机器上有 python,但他们可能有也可能没有 xlrd 模块.

Hi as a python newbie I have written a small python application that can convert an excel worksheet into a sqlite database table. Its not a terribly complex application but it does make use of external modules/package like xlrd (http://pypi.python.org/pypi/xlrd) which I had to download and install when writing my app. Now that is all done I would like to distribute it amongst my friends, all windows users, while they have python on their machines, they may or may not have the xlrd modules.

我想打包我的应用程序,确保它包含运行所需的一切,并与我的朋友分享最终的 .zip 文件,以便他们可以使用该应用程序.是否有一个很好的教程,介绍如何使用所有必要的外部模块/包打包 Python 应用程序,以便其他 Windows 用户可以轻松运行我的应用程序.

I would like to package my app, make sure it includes everything that it needs to run, and share the final .zip file with my friends so they can use the application. Is there a good tutorial that covers how to package a python application, with all the necessary external modules/packages, so that another windows user, can easily run my application.

我一直听到有关 disutils 的消息,谁能指点我一些好的教程,或任何其他 Python 打包教程,以展示如何将所有内容放入一个简单的易于分发的文件中.非常感谢

I keep hearing about disutils, can anyone point me to some good tutorials, or any other python packaging tutorials that show how to get everything into a simple easy to distribute file. Many thanks

注意:我还想在我的应用程序中包含 sqlite 数据库文件,因此最终用户不必担心任何事情

Note: I also want to include the sqlite database file with my application, so the end user doesn't have to worry about anything

推荐答案

首先下载 Pyinstaller 并将其保存在某处.然后,如果您运行的是 Python 2.6 或 2.7,请安装 pywin32.

First download Pyinstaller and save it somewhere. Then, if you're running Python 2.6 or 2.7 go and install pywin32.

为您的输出文件创建一个目录.

Go create a directory for your output file.

打开命令提示符并输入以下内容:

Open Command prompt and enter the fallowing:

python path/to/pyinstaller/pyinstall.py file/to/be/converted.py --onefile 

如果要添加图标,请添加 --icon 参数.

If you want to add an icon, add the --icon argument.

如果要隐藏 CMD 窗口,请添加 --windowed 参数.

If you want it to hide the CMD window add the --windowed argument.

所以如果你想让它使用一个图标并隐藏 CMD 窗口,它看起来像这样:

So if you wanted it to use an icon and hide the CMD window it would look like this:

python path/to/pyinstaller/pyinstall.py file/to/be/converted.py --onefile --icon="path/to/icon.ico" --windowed

--onefile 参数将所有内容保存到一个文件中,如果没有它,输出将是很多文件.

The --onefile argument makes the saves everything into one file, without it, the output would be would be a lot of files.

输出保存在它使用的目录中的dist"文件夹中.

The output is saved in the "dist" folder in the directory it was using.

将 python 脚本转换为 .exe 后,将其与任何其他文件一起放入 .zip 文件中(在您的情况下为 squite 数据库文件),您可以将其提供给任何人而无需他们拥有根本没有 Python.

After you convert the python script in to an .exe, put it in a .zip file along with any other files you need (in your case the squite database file) and you can give it to anyone without them needing to have Python at all.

如果您想要一个程序为您完成这一切,您可以下载一个名为 PTEC.

If you want a program to do this all for you, you can download a program called PTEC.

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

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