Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Last active June 6, 2024 11:48
Show Gist options
  • Save peteristhegreat/0a05d7029befc5c2a302 to your computer and use it in GitHub Desktop.
Save peteristhegreat/0a05d7029befc5c2a302 to your computer and use it in GitHub Desktop.
Using `PyQt` with `py2exe` example with runtime plugins, like icons

Start with miniconda installed. Use an IDE like PyCharm if you can.

Ensure conda is in the path

Create a PyCharm project Create a conda environment through PyCharm

Activate the new environment in a terminal (aka the command prompt)

activate pyqt-env

Install pyqt=4 and py2exe 6.9

conda install pyqt=4
conda install -c sasview py2exe

Create a setup.py file at the project root

from distutils.core import setup
import py2exe

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

Run Py2Exe to create the dist folder

python setup.py py2exe

This creates a folder called dist... zip this folder up and it is your distributable

See Also

from distutils.core import setup
import py2exe
from os.path import join
_PYQT4DIR = r'C:\Anaconda\Lib\site-packages\PyQt4'
data_files =[('imageformats',[join(_PYQT4DIR,'plugins\imageformats\qico4.dll')]),
('.',["TestUsb.exe","icon.ico"])
]
setup(
# window = [ ### start using this when the commandline feedback is unnecessary
console = [
{
"script": "example.py", ### Main Python script
"icon_resources": [(0, "icon.ico")] ### Icon to embed into the PE file.
}
],
name="example",
version="0.1",
author="John Doe",
author_email="jdoe@example.com",
url="http://example.com/",
license="GNU General Public License (GPL)",
data_files=data_files,
options={"py2exe": {"skip_archive": True,
"dll_excludes": ["MSVCP90.dll", "HID.DLL", "w9xpopen.exe"],
"includes": ["sip"]}})
@SuzukaDev
Copy link

This was very helpful, thanks mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment