py2exe打包后发现 no model named sip问题(使用pyqt时)的解决方法

时间:2022-05-13 11:33:30

使用pyqt完成窗体界面很方便,但是打包成exe之后会有问题,在网上找到解决办法如下:

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 from distutils.core import setup
2 import py2exe
3
4 setup(windows=[{"script" : "app.pyw"}], options={"py2exe" : {"includes" : ["sip", "PyQt4._qt"]}})