Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executables built with cx_freeze broken after On-host pixels to PDF conversion PR was merged #974

Closed
jkarasti opened this issue Oct 29, 2024 · 3 comments · Fixed by #998
Closed
Labels
bug Something isn't working

Comments

@jkarasti
Copy link
Contributor

jkarasti commented Oct 29, 2024

What happened?

On-host pixels to PDF conversion merged in #748 uncovered an incompatibility between pumypdf and cx_freeze which causes an error when running dangerzone.exe or dangerzone-cli.exe built with cx_freeze.

operating system version

Windows 10 Pro 22H2 (OS Build 19045.5073)

Dangerzone version

Top of main branch

Docker info

No response

Document conversion logs

No response

Additional info

Here's the error log I got:

Traceback (most recent call last):
  File "C:\Users\juhok\AppData\Local\pypoetry\Cache\virtualenvs\dangerzone-_8ncJGJf-py3.12\Lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 140, in run
    module_init.run(f"__main__{name}")
  File "C:\Users\juhok\AppData\Local\pypoetry\Cache\virtualenvs\dangerzone-_8ncJGJf-py3.12\Lib\site-packages\cx_Freeze\initscripts\console.py", line 25, in run
    exec(code, main_globals)
  File "install\windows\dangerzone-cli.py", line 1, in <module>
  File "C:\GitHub\dangerzone\dangerzone\__init__.py", line 27, in <module>
    from .cli import cli_main as main
  File "C:\GitHub\dangerzone\dangerzone\cli.py", line 10, in <module>
    from .isolation_provider.container import Container
  File "C:\GitHub\dangerzone\dangerzone\isolation_provider\container.py", line 12, in <module>
    from .base import IsolationProvider, terminate_process_group
  File "C:\GitHub\dangerzone\dangerzone\isolation_provider\base.py", line 12, in <module>
    import fitz
  File "C:\Users\juhok\AppData\Local\pypoetry\Cache\virtualenvs\dangerzone-_8ncJGJf-py3.12\Lib\site-packages\fitz\__init__.py", line 2, in <module>
    from pymupdf import *
  File "C:\Users\juhok\AppData\Local\pypoetry\Cache\virtualenvs\dangerzone-_8ncJGJf-py3.12\Lib\site-packages\pymupdf\__init__.py", line 21706, in <module>
    from . import utils
ImportError: cannot import name 'utils' from partially initialized module 'pymupdf' (most likely due to a circular import) (C \GitHub\dangerzone\build\exe.win-amd64-3.12\lib\pymupdf\__init__.pyc)
@jkarasti jkarasti added the bug Something isn't working label Oct 29, 2024
@almet
Copy link
Contributor

almet commented Oct 29, 2024

Hey, thanks for the report. I'm curious: how did you run the dangerzone.exe, and did you update the installed dependencies? It seems weird that this error wasn't catched by the CI!

@jkarasti
Copy link
Contributor Author

jkarasti commented Oct 29, 2024

Hey, thanks for the report. I'm curious: how did you run the dangerzone.exe

I've built the executables following the Windows section in BUILD.md with poetry run python .\setup-windows.py build and then tried to launch dangerzone.exe inside exe.win-amd64-3.12 but hit the above error. Interestingly enough, running Dangerzone with poetry run .\dev_scripts\dangerzone.bat instead of the executables produced by cx_freeze works a-okay.

Did you update the installed dependencies?

I've tried to get Dangerzone running with a myriad of combinations of versions of cx_freeze between 7.2.0 and latest and pymupdf between 1.23.3 and latest. As far as I can tell, Dangerzone runs from commit 4abd472 (commit before on-host PR) regradless of which version of cx_freeze or pymupdf is installed

It seems weird that this error wasn't catched by the CI!

At a cursory glance, I don't think CI runs the .exe that cx_freeze builds, so I don't think this particular edge case can get caught in the first place.

@apyrgio
Copy link
Contributor

apyrgio commented Oct 29, 2024

Ok, I just managed to reproduce it on my Windows machine. I have notified the developer of cx-Freeze to fix the underlying issue: marcelotduarte/cx_Freeze#2653

(well, the real underling issue is PyMuPDF's... particular way of using __init__.py, but I digress)

You can apply this workaround in the meantime to make progress:

diff --git a/setup-windows.py b/setup-windows.py
index deae943..70291ad 100644
--- a/setup-windows.py
+++ b/setup-windows.py
@@ -4,7 +4,7 @@ from cx_Freeze import Executable, setup
 with open("share/version.txt") as f:
     version = f.read().strip()
 
-packages = ["dangerzone", "dangerzone.gui"]
+packages = ["dangerzone", "dangerzone.gui", "pymupdf.utils"]
 
 setup(
     name="dangerzone",

As always, muchas gracias for the help on the Wix front. I plan to be more involved with your PR once we're done with the 0.8.0 release.

@jkarasti jkarasti changed the title On-host pixels to PDF conversion broke executables built with cx_freeze Executables built with cx_freeze broken after On-host pixels to PDF conversion PR was merged Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants