博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Shipping your PyQt app for windows
阅读量:7077 次
发布时间:2019-06-28

本文共 4403 字,大约阅读时间需要 14 分钟。

Shipping your PyQt app for windows


Posted: 2011-07-24 21:20:00   |     |  More posts about

I have written about this in the past, with the general conclusion being "it's a pain in the ass".

So, now, here is how it's done.

  1. Start with a working PyQt application. In this example, I will use mostly because:
    1. It is a working PyQt application.
    2. It uses a big chunk of PyQt
    3. It's easy to test
  2. Now you need a setup.py. Here's one that works, with extensive commments.
# We will be using py2exe to build the binaries.# You may use other tools, but I know this one.from distutils.core import setupimport py2exe# Now you need to pass arguments to setup# windows is a list of scripts that have their own UI and# thus don't need to run in a console.setup(windows=['devicenzo.py'],      options={
# And now, configure py2exe by passing more options; 'py2exe': {
# This is magic: if you don't add these, your .exe may# or may not work on older/newer versions of windows. "dll_excludes": [ "MSVCP90.dll", "MSWSOCK.dll", "mswsock.dll", "powrprof.dll", ],# Py2exe will not figure out that you need these on its own.# You may need one, the other, or both. 'includes': [ 'sip', 'PyQt4.QtNetwork', ],# Optional: make one big exe with everything in it, or# a folder with many things in it. Your choice# 'bundle_files': 1, } },# Qt's dynamically loaded plugins and py2exe really don't# get along.data_files = [ ('phonon_backend', [ 'C:\Python27\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll' ]), ('imageplugins', [ 'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qgif4.dll', 'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qjpeg4.dll', 'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qsvg4.dll', ]),],# If you choose the bundle above, you may want to use this, too.# zipfile=None,)
  1. Run python setup.py py2exe and get a dist folder full of binary goodness.

And that's it. Except of course, that's not it.

What this will do is create a binary set, either a folder full of things, or a single EXE file. And that's not enough. You have to consider at least the following:

  1. Put everything in resource files: images, qss files, icons, etc. Every file your app needs? Put it in a resource file and load it from there. That way you don't have to care about them if you go the "one exe" road.
  2. Compile .ui files to .py (same reason)
  3. Figure out if you use Qt's plugins, and make them work. This includes: using Phonon, using QtSQL, and using any image formats other than PNG.

After you have that, are you done? NO!

Your windows user will want an installer. I am not going to go into details, but I had a good time using BitRock's InstallBuilder for Qt. It's a nice tool, and it works. That's a lot in this field.

But is that all? NO!

You have to take care of the Visual Studio Runtime. My suggestion? Get a copy of the 1.1MB vcredist_x86.exe (not the larger one, the 1.1MB one), and either tell people to install it manually, or add it to your installer. You are legally allowed (AFAIK) to redistribute that thing as a whole. But not what's in it (unless you have a VS license).

And we are done? NO!

Once you run your app "installed", if it ever prints anything to stderr, you will get either a dialog telling you it did, or worse (if you are in aything newer than XP), a dialog telling you it can't write to a log file, and the app will never work again.

This is because py2exe catches stderr and tries to save it on a logfile. Which it tries to create in the same folder as the binary. Which is usually not allowed because of permissions.

Solution? Your app should never write to stderr. Write an excepthook and catch that. And then remove stderr or replace it with a log file, or something. Just don't let py2exe do it, because the way py2exe does it is broken.

And is that it?

Well, basically yes. Of course you should get 4 or 5 different versions of windows to test it on, but you are pretty much free to ship your app as you wish. Oh, mind you, don't upload it to downloads.com because they will wrap your installer in a larger one that installs bloatware and crap.

So, there you go.

转载地址:http://bfpml.baihongyu.com/

你可能感兴趣的文章
获取网页数据的例子
查看>>
struts2的配置文件
查看>>
JSP第5次测试---测试分析
查看>>
tomcat容器
查看>>
Nginx配置文件详细说明
查看>>
同时可以修改时间和日期的datetime_select and 有关时间的转换
查看>>
IOS Orientation, 想怎么转就怎么转~~~
查看>>
Finding Lines
查看>>
服务提供者及门面
查看>>
POJ-1611-The Suspects(并查集)
查看>>
用VC生成 IDispatch 包装类
查看>>
xcode5.1上真机调试报告No architectures to compile for...的解决办法
查看>>
Codeforces 106A:Card Game
查看>>
算法导论读书笔记-第十四章-数据结构的扩张
查看>>
HttpClient使用详解
查看>>
char、varchar、nchar、nvarchar的区别
查看>>
锐捷、赛尔认证MentoHUST
查看>>
前后台传值 201...
查看>>
POJ 2133 暴搜
查看>>
BZOJ 1379 模拟退火
查看>>