简体   繁体   中英

py2exe: Generated EXE doesn't load

My PyQt4 application's py2exe binary flashes briefly on the screen and then disappears. I have no idea why, but here's what happened before:

My application didn't display SVG images when loading (from the Exe), so I dug around a bit and saw that I had to modify my setup.py to include a qt.conf and some DLLs.

Then the binary just stopped loading after the qt.conf was included.

I played with the qt.conf and found that my Exe doesn't load unless I delete the qt.conf , so I think it is malformed.

Here's my qt.conf :

[Paths]
Plugins = plugins

I tried it with absolute paths, forward slashes, back slashes, you name it. I even copied the entire PyQt4 folder with this file and still no luck.

If it's relevant, here's my setup.py :

import os, sys, glob

from distutils.core import setup
from py2exe.build_exe import py2exe

def find_data_files(source,target,patterns):
  if glob.has_magic(source) or glob.has_magic(target):
    raise ValueError("Magic not allowed in src, target")

  ret = {}

  for pattern in patterns:
    pattern = os.path.join(source,pattern)

    for filename in glob.glob(pattern):
      if os.path.isfile(filename):
        targetpath = os.path.join(target,os.path.relpath(filename,source))
        path = os.path.dirname(targetpath)
        ret.setdefault(path,[]).append(filename)
  return sorted(ret.items())

setup(
#  zipfile = None,
  data_files = find_data_files('', '', ['bin/*', 'plugins/iconengines/*', 'qt.conf']),
  windows = [{'script': 'main.py'}],
#  cmdclass = {'py2exe': Py2exe},
  options = {
  'py2exe': {
    'bundle_files': 1,
    'includes': ['sip'],
    'dll_excludes': ['MSVCP90.dll']#, 'qsvgicon4.dll']
  }
  }
)

If I remember right, Py2exe is discontinued, so it's really not safe to use.

I use cx_Freeze, which has never failed me once in working. It might help you out too.

Also, remember that paths are different when frozen vs a script. Typically, you need os.path.dirname(sys.executable) for frozen (which you can test for using hasattr(sys, 'frozen') ), vs a typical os.path.dirname(__file__) .

Also, make sure you're copying the imageformats qt plugin directory. It has caused problems for people before. The imageformats folder is where the svg plugin resides in as well. You'll also need to copy PyQt4.QtXml and PyQt4.QtSvg dll's/so's over as well (required by svg plugin).

My project has a build_binary.py file for cx_Freeze which autodetects the plugin directory and copies the required stuff over. It may help you out to take a look at it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM