Differences between revisions 13 and 14
Revision 13 as of 2011-04-21 13:52:51
Size: 3144
Comment:
Revision 14 as of 2011-10-16 21:33:42
Size: 3110
Comment:
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
  File "form1.pyc", line 11, in ?
File "qt.pyc", line 9, in ?
File "qt.pyc", line 7, in __load
ImportError: No module named sip
}}}
  File "form1.pyc", line 11, in ?  File "qt.pyc", line 9, in ?  File "qt.pyc", line 7, in __load ImportError: No module named sip }}}
Line 14: Line 10:
#!python
from py2exe.build_exe import py2exe
from distutils.core import setup
setup( console=[{"script": "main.py"}] )
}}}
#!python from py2exe.build_exe import py2exe from distutils.core import setup setup( console=[{"script": "main.py"}] ) }}}
Line 26: Line 18:
from distutils.core import setup
import py2exe
setup(windows=[{"script":"main.py"}], options={"py2exe":{"includes":["sip"]}})
}}}
from distutils.core import setup import py2exe setup(windows=[{"script":"main.py"}], options={"py2exe":{"includes":["sip"]}}) }}}
Line 36: Line 25:
Line 37: Line 27:
ImportError: No module named _qt
}}}

ImportError: No module named _qt }}}
Line 43: Line 30:
{{{#!python
from distutils.core import setup
import py2exe

setup(windows=[{"script" : "app.pyw"}], options={"py2exe" : {"includes" : ["sip", "PyQt4._qt"]}})
}}}
{{{
#!python   from distutils.core import setup import py2exe  setup(windows=[{"script" : "app.pyw"}], options={"py2exe" : {"includes" : ["sip", "PyQt4._qt"]}}) }}}
Line 52: Line 34:
Line 61: Line 44:
But the correct way to do this is to use [[data_files|data_files]] in your setup.py But the correct way to do this is to use [[data_files]] in your setup.py
Line 63: Line 47:
data_files = [
('phonon_backend', [
'C:\Python26\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll'
])
]
}}}
data_files = [  ('phonon_backend', [  'C:\Python26\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll'  ]) ] }}}
Line 71: Line 49:
Line 76: Line 53:
This will work with bundle_files as well, but you need to exclude the Qt DLLs from bundle (using the {{{dll_excludes}}} option) and add them to the directory with the executable through some other mechanism (such as {{{data_files}}}).  This will work with bundle_files as well, but you need to exclude the Qt DLLs from bundle (using the {{{dll_excludes}}} option) and add them to the directory with the executable through some other mechanism (such as {{{data_files}}}).

Error message

  File "form1.pyc", line 11, in ?   File "qt.pyc", line 9, in ?   File "qt.pyc", line 7, in __load ImportError: No module named sip 

Solution

python setup.py py2exe --includes sip

setup.py

   1 

Reference

I found this tips here : http://nerdierthanthou.nfshost.com/2005/03/image-resizer.html

There is a full code sample.

Another Solution to the same problem:

from distutils.core import setup import py2exe setup(windows=[{"script":"main.py"}], options={"py2exe":{"includes":["sip"]}}) 

I found that on the web, unfortunately don't know anymore where, but it also works for me!

Obviously is the second part only a way to get the " --includes sip" parameter directly into the script, but the use of "windows" instead of "console" doesn't open a console window, but immediately a Qt window in my case.

Fix for PyQt4

If you get the following error:

ImportError: No module named _qt 

The solution is to add PyQt4._qt to the setup function (see bellow). I found the solution for the problem here.

   1 

Using PyQt4 with Databases

When deploying applications which use PyQt4 and SQLite:

  • Add "PyQt4.QtSql' to the setup includes.

  • Copy the contents of PyQt4\plugins\sqldrivers to <appdir>\sqldrivers. It did not work for me in any subdirectory including the zipfile directory. For SQLite I only needed to copy qsqlite4.dll.

  • A separate copy of sqlite3.dll is not needed.

Tips: use data_files for this. See below

PyQt4 and Phonon

In a similar manner as using PyQt4 and SQlite (from pyqt), one need to add an extra step to use Phonon and copy PyQt4\plugins\phonon_backend directory into your dist directory. Otherwise you get an error: "phonon backend could not be loaded"

But the correct way to do this is to use data_files in your setup.py

data_files = [             ('phonon_backend', [                 'C:\Python26\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll'                 ]) ] 

PyQt4 and image loading (JPG, GIF, etc)

PyQt4 uses plugins to read those image formats, so you'll need to copy the folder PyQt4\plugins\imageformats to <appdir>\imageformats. Like in the above cases, you can use data_files for this. This won't work with bundle_files on.

If the plugins are not reachable, then QPixmap.load/loadFromData will return False when loading an image in those formats.

This will work with bundle_files as well, but you need to exclude the Qt DLLs from bundle (using the dll_excludes option) and add them to the directory with the executable through some other mechanism (such as data_files).

Py2exeAndPyQt (last edited 2011-10-16 21:42:58 by MircoAckermann)