Tuesday, April 23, 2024
HomePythonUtilizing py2exe the proper approach

Utilizing py2exe the proper approach


Hello guys how are you? I hope all of you might be positive. Just lately I used to be engaged on a PyQt venture. The venture was youtube-dl-GUI. It’s a GUI for the ever well-liked youtube-dl venture.

After writing all of the code I made a decision to make an exe with a view to ease the deployment of my venture on home windows. For this goal I made a decision to make use of py2exe which suited greatest to my wants. Nevertheless it’s essential to know that py2exe isn’t the one Python to exe compiler on the market. Among the different well-liked Python exe makers on the market are pyinstaller and cx_freeze.

These exe makers merely compile our script to bytecode and packages it with a Python execultable in order that our program/script can work on these Home windows’ PC’s which don’t have Python put in.

Nevertheless through the exe making course of I confronted a few issues and there was not a single blogpost wherever devoted to fixing all of these issues. On this put up I’ll attempt to checklist all of these issues and also will checklist the options which I used to resolve these issues.

MSVCP90.dll lacking

The primary error which I got here throughout was the MSVCP90.dll lacking error. I searched on Google and got here to know that I wanted to put in the Microsoft Visible C++ 2008 Redistributable Package deal with a view to remedy the issue. I got here to know that it was already put in on my system however I nonetheless reinstalled it simply to make certain. After reinstallation I attempted to run py2exe once more however the issue nonetheless endured. After looking out endlessly for an hour or so I got here ahead to an answer. The answer was to go looking and duplicate MSVCP90.dll from my system folder to Python’s DLL folder which in my case was C:Python27DLLs (it is perhaps totally different in your system). I utilized the answer and Voila it labored.

No module named sip

One other error I got here throughout whereas compiling a PyQt4 script was the ImportError: No module named sip error. This one was fairly straightforward to resolve. The answer was situated on py2exe web site. One resolution was to make use of py2exe like this:

python setup.py py2exe --includes sip

The content material of the setup.py have been as follows:

from py2exe.build_exe import py2exe
from distutils.core import setup
setup( console=[{"script": "main.py"}] )

One other resolution was to switch the setup.py file like this:

from distutils.core import setup
import py2exe
setup(home windows=[{"script":"main.py"}], choices={"py2exe":{"consists of":["sip"]}})

After which run py2exe like this:

python setup.py py2exe

These options solved the issue for me.

No photos displayed in PyQt

This resolution was once more arduous to seek out however nonetheless I used to be capable of finding it. The answer was to bundle the PyQt picture plugins with the applying. I added this in my setup.py file:

DATA=[('imageformats',['C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qjpeg4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qgif4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qico4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qmng4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qsvg4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qtiff4.dll'
    ])]
setup( 
    #...
    #...
    data_files = DATA,
)

This solved the issue for me.

Making a single exe

Beforehand I take advantage of innosetup to make an installer however later I got here throughout one other technique which allowed me to make use of py2exe to straight create a bundled exe which might be run by double clicking. With a purpose to obtain this I modified my setup.py file like this:

from distutils.core import setup
import py2exe, sys, os
#...
#...
setup(
    choices = {'py2exe': {'bundle_files': 1, 'compressed': True,"consists of":["sip"]}},
    #...
    #...
)

Please observe that if you wish to make an installer you want to use innosetup or an equal.

Lastly

After making all these edits I ended up with one thing like this:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

DATA=[('imageformats',['C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qjpeg4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qgif4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qico4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qmng4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qsvg4.dll',
    'C:Python27/Lib/site-packages/PyQt4/plugins/imageformats/qtiff4.dll'
    ])]

setup(
    choices = {'py2exe': {'bundle_files': 1, 'compressed': True,"consists of":["sip"]}},
    home windows = [{'script': "main.py"}],
    zipfile = None,
    data_files = DATA,
)

I hope this put up allowed you to resolve a few of your py2exe issues. In case you want any additional assist then remark under, shoot me an electronic mail or tweet it on to me.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments