Search code examples
pythonpython-3.xpyinstaller

Problems with compiling .py to .exe


I try to compile a .py file to a .exe file with the pyinstaller, but I allways get this warning in the terminal:

c:\users\cpuhv\appdata\local\programs\python\python39\lib\site-packages\setuptools\distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This u
sage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
  warnings.warn(

When I try to run the .exe file I get a Warning Window with the text: "Failed to execute script"

Does anyone know how to fix this?


Solution

  • I found a solution for you. Onefile and all. I'm leaving my previous answer as even though it is not ideal, it may be helpful to someone.

    Follow the instructions found here: https://github.com/AlJohri/docx2pdf/issues/5

    pyinstaller is missing hook script to run docx2pdf.

    save hook-docx2pdf.py to \Lib\site-packages\PyInstaller\hooks, Copy the text below in:

    from PyInstaller.utils.hooks import collect_all

    hiddenimports = collect_all('docx2pdf')

    I had to exit and restart PyCharm afterwards, but that fixed all errors relating to docx2pdf import troubles.

    After that, I was running into a lot of errors relating to PyQt. I've had trouble with PyQt and Pyinstaller working together in the past.

    If you downgrade from PyQt6 to PyQt5 though, all of your problems will be solved. Then simply change your imports list to import from PyQt5.

    Then run pyinstaller --onefile -w main.py

    It seems that Pyinstaller and PyQt6 are not fully compatible yet.

    If this worked, I would appreciate if you would mark this as the accepted answer.