marcelotduarte / cx_Freeze

cx_Freeze creates standalone executables from Python scripts, with the same performance, is cross-platform and should work on any platform that Python itself works on.
https://marcelotduarte.github.io/cx_Freeze/
Other
1.36k stars 220 forks source link

PyGObject hook broke in 7.1.0 #2424

Closed black-sliver closed 5 months ago

black-sliver commented 5 months ago

Describe the bug Freezing in a venv that has pygobject installed via pip will fail.

Running DISTUTILS_DEBUG=1 python setup.py build_exe gives

cx_Freeze.exception.OptionError: cannot find file/directory named /home/<user>/<project>/venv/lib/girepository-1.0/Atk-1.0.typelib

To Reproduce On a fresh Ubuntu 20.04 (have not tested others, but likely independent of OS version) run

sudo apt install python3-venv
sudo apt install python3-dev python3-gi libgirepository1.0-dev libcairo2-dev  # this pulls all dependencies for pip install pygobject
sudo apt install gir1.2-atk-1.0  # this would provide the atk .typelib, but was not required with 7.0.0
python3 -m venv venv
source venv/bin/activate
pip install pygobject
echo 'import gi; print("Hello World!")' > main.py
pip install cx_freeze==7.1.0
cxfreeze --script main.py build_exe  # fails with error shown above
pip install cx_freeze==7.0.0
cxfreeze --script main.py build_exe  # succeeds

Expected behavior Most likely correct would be to not include the atk typelib, but if this is by choice, then the lookup path should be fixed, so freezing does not fail.

Desktop (please complete the following information):

marcelotduarte commented 5 months ago

Please test the patch:

pip uninstall cx_Freeze
pip install git+https://github.com/marcelotduarte/cx_Freeze.git@refs/pull/2425/head
black-sliver commented 5 months ago

The application successfully builds and runs now.

As a side note find build/exe.linux* -name "*.typelib" does not find anything with either 6.15.2, 7.0.0 or 7.2.0.dev0 with the setup we have.

It however seems to pick up system-wide installed typelibs, which I believe is fine for our application, because pygobject is an optional/alternative dependency for some functionality, depending on which system it ends up running on. But I wanted to put that here in case the expectation is that all typelibs are included now.

marcelotduarte commented 5 months ago

The expectation is that some typelibs will be installed, more precisely those on this list, if available: https://github.com/marcelotduarte/cx_Freeze/blob/b17c3db943d4e5364da1979fd256f80661ecee6c/cx_Freeze/hooks/gi.py#L45-L58

marcelotduarte commented 5 months ago

Release 7.1.0-post0 is out! Documentation