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

Extra files being include due to PyQt5 hook when PyQt5 in zip file #1372

Closed cainesi closed 2 years ago

cainesi commented 2 years ago

Describe the bug After commit 7fbf1ba71d601c382dddb0c735f5827336f416eb, extra files are copied into Qt plugins directories. The extra files are Qt5 dynamically linked libraries (e.g., Qt5Core.dll, QtGui.dll). I suspect that this is not a PyQt-specific problem, but just related to the change in now dependencies are located for included binary files. I have not had time to figure out exactly what is going on.

To Reproduce Freeze an application where the hook for a PyQt5 plugin in triggered. Have PyQt5 included in the zip file.

Expected behavior Only the contents of the relevant plugins directory are copied into the frozen application.

Desktop (please complete the following information): Windows 10, amd64 Starting with commit 7fbf1ba71d601c382dddb0c735f5827336f416eb (between 6.9 and 6.10). Python version, e.g. 3.8.

Additional context Commit 7fbf1ba71d601c382dddb0c735f5827336f416eb is dealing with detecting dependencies, so it makes sense that it might have thrown up an issue like this.

marcelotduarte commented 2 years ago

In PR #1344 there are instructions to disable this experimental behavior if you need it.

marcelotduarte commented 2 years ago

@cainesi Hi! Can you test the PR #1623?

I tested it with pyqt/pyside samples. Can you test with your project(s)?

To install the latest development build:

pip install --pre --extra-index-url https://marcelotduarte.github.io/packages/ cx_Freeze

cainesi commented 2 years ago

I am getting a failure with the exception "ValueError: A distribution name is required." The exception is triggered when Module.update_distribution is called on "importlib.metadata". update_distribution gets a distribution object, but distribution.name==None so the subsequent call to importlib_metadata.requires(distribution.name) raises an exception.

But it looks like this issue existed in cx_freeze 6.11, and not just the latest development version. Will take a look later to see if I can figure out what's going on. Might be a problem on my end, and not with cx_freeze.

marcelotduarte commented 2 years ago

Show me a traceback.

cainesi commented 2 years ago

Here is a traceback.

stacktrace.txt

I'm pretty sure I had cx_freeze 6.11 working earlier, so not sure why that changed. Maybe I changed the version of one of the other dependencies?

marcelotduarte commented 2 years ago

If you are using python 3.10, uninstall importlib-metadata and try to build. If previous version, try to use a importlib-metadata < 5.0 (or ==4.8.3)

Probably this is the root cause at v 4.12.0: https://github.com/python/importlib_metadata/blob/main/CHANGES.rst#v4120

marcelotduarte commented 2 years ago

PR #1625 added to development build:

pip uninstall -y cx_Freeze pip install --pre --extra-index-url https://marcelotduarte.github.io/packages/ cx_Freeze

cainesi commented 2 years ago

Thanks for taking a look.

I'm using Python 3.9. I think you are right about 4.12--no error when I use importlib-metadata==4.11.4, but the error appears with 4.12.

However, the same error still happens when I use the metadata branch and the latest development branch. Will late a closer look in a bit.

cainesi commented 2 years ago

Hi @marcelotduarte. Thanks for looking at this so quickly.

I took a look at the #1625, and I think you were dealing with the ValueError too soon. For me, the error was arising in the second try block in update_distribution. PR #1630 has alternative code that did resolve the error for me. (If the first try block could also through a ValueError, then maybe we need to deal with it in both spots.)

However, I still think there may be an underlying problem (very likely on my end). I found that i have another old virtualenv, with the same stuff installed, and cx_freeze ran without the fix. For some reason creating Module("importlib.metadata") succeeded in that other virtualenv, so this issue with the ValueError never got triggered. I'll try to dig in later and see what's going on.

cainesi commented 2 years ago

I think this one should be re-openned, per my last comment.

marcelotduarte commented 2 years ago

PR #1625 deals with try block in update_distribution, line 164 and other in line 174. PR #1630 deals only with line 164 (163), so 1625 supersedes 1630,

marcelotduarte commented 2 years ago

I think this one should be re-openned, per my last comment.

Please open a new issue as it is not related to the issue with pyqt5.

marcelotduarte commented 2 years ago

But what must be happening, must be some locked file. Check the versions of setuptools, pip. There are versions that caused problems.

cainesi commented 2 years ago

Okay. Opened new issue #1631. Locked files might be it--there's definitely something weird happening locally with the cx_freeze install. I'll try to figure it out later (no need for you to waste time on it).

Pip 22.2.2, setuptools: 60.10.0.

marcelotduarte commented 2 years ago

I do not remember if setup 60x has incompatibilities, but in 61 to 65 I had to workaround. I recommend that you uninstall cx_Freeze, setuptools, importlib-metadata. See if there are lost files in site-packages, clean up these files (.dist-info, .egg, etc) and reinstall. Local .egg for your project must be cleaned too.

cainesi commented 2 years ago

Thanks! I created the virtualenv from scratch and then fixed the issue I was having.