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

Problems running pyqt tutorial on cx_freeze 7.2.4 #2676

Open
GabrielMarcilio opened this issue Nov 11, 2024 · 8 comments
Open

Problems running pyqt tutorial on cx_freeze 7.2.4 #2676

GabrielMarcilio opened this issue Nov 11, 2024 · 8 comments

Comments

@GabrielMarcilio
Copy link

Sorry if this is not the correct place to ask for it. I believe that the pyqt sample is outdated/missing some steps

I can run the pyqt sample application (test_pyqt.py) in dev mode and run the created binary correctly when using cx_freeze 6.15.12 and pyqt 5.15.9

However if i use cx_freeze 7.2.4 and the same pyqt, when i run the created binary the application crashes when loading pyqt:

import_pyqt_error

The only change that i made from cx_freeze 6,15,12 to 7.2.4 was in setup.py file the executable base changed from "Win32GUI" to "gui".

Can you please confirm that the pyqt sample works with cx_freeze 7.2.4?

Thanks

@marcelotduarte
Copy link
Owner

Yes, it works for me. I just tested it now.

  • Platform information: Windows
  • OS architecture (e.g. amd64):
  • cx_Freeze version [e.g. 6.11]: 7.2.5
  • Python version [e.g. 3.10]: 3.10
  • Environment: pip and conda-forge
    pyqt5-0-test_pyqt5-win-amd64-3_10

@GabrielMarcilio
Copy link
Author

GabrielMarcilio commented Nov 13, 2024

Thanks for the quick response Marcelo. Can you confirm the pyqt version that you used?

I am using a conda environment here with:
conda create --name test_qt python=3.10.4 cx_freeze=7.2.5 pyqt=5.15.9

@marcelotduarte
Copy link
Owner

I always use the latest packages to test.
conda list

  Python 3.10.15 | packaged by conda-forge | (main, Oct 16 2024, 01:15:49) [MSC v.1941 64 bit (AMD64)]
  
  # packages in environment at C:\Miniconda\envs\windows-latest-3.10:
  #
  # Name                    Version                   Build  Channel
  bzip2                     1.0.8                h2466b09_7    conda-forge
  ca-certificates           2024.8.30            h56e8100_0    conda-forge
  cabarchive                0.2.4              pyhd8ed1ab_0    conda-forge
  cx_freeze                 7.2.5           py310ha8f682b_0    conda-forge
  cx_logging                3.2.1           py310ha8f682b_0    conda-forge
  filelock                  3.16.1             pyhd8ed1ab_0    conda-forge
  glib                      2.82.2               h7025463_0    conda-forge
  glib-tools                2.82.2               h4394cf3_0    conda-forge
  gst-plugins-base          1.24.7               hb0a98b8_0    conda-forge
  gstreamer                 1.24.7               h5006eae_0    conda-forge
  icu                       75.1                 he0c23c2_0    conda-forge
  krb5                      1.21.3               hdf4eb48_0    conda-forge
  libclang13                19.1.3          default_ha5278ca_0    conda-forge
  libffi                    3.4.2                h8ffe710_5    conda-forge
  libglib                   2.82.2               h7025463_0    conda-forge
  libiconv                  1.17                 hcfcfb64_2    conda-forge
  libintl                   0.22.5               h5728263_3    conda-forge
  libintl-devel             0.22.5               h5728263_3    conda-forge
  libjpeg-turbo             3.0.0                hcfcfb64_1    conda-forge
  liblief                   0.14.1               he0c23c2_2    conda-forge
  libogg                    1.3.5                h2466b09_0    conda-forge
  libpng                    1.6.44               h3ca93ac_0    conda-forge
  libsqlite                 3.47.0               h2466b09_1    conda-forge
  libvorbis                 1.3.7                h0e60522_0    conda-forge
  libzlib                   1.3.1                h2466b09_2    conda-forge
  openssl                   3.4.0                h2466b09_0    conda-forge
  packaging                 24.1               pyhd8ed1ab_0    conda-forge
  pcre2                     10.44                h3d7b363_2    conda-forge
  pip                       24.3.1             pyh8b19718_0    conda-forge
  ply                       3.11               pyhd8ed1ab_2    conda-forge
  py-lief                   0.14.1          py310h9e98ed7_2    conda-forge
  pyqt                      5.15.9          py310h1fd54f2_5    conda-forge
  pyqt5-sip                 12.12.2         py310h00ffb61_5    conda-forge
  python                    3.10.15         hfaddaf0_2_cpython    conda-forge
  python_abi                3.10                    5_cp310    conda-forge
  qt-main                   5.15.15              h264fbc2_0    conda-forge
  setuptools                75.3.0             pyhd8ed1ab_0    conda-forge
  sip                       6.7.12          py310h00ffb61_0    conda-forge
  striprtf                  0.0.27             pyhd8ed1ab_0    conda-forge
  tk                        8.6.13               h5226925_1    conda-forge
  toml                      0.10.2             pyhd8ed1ab_0    conda-forge
  tomli                     2.1.0              pyhff2d567_0    conda-forge
  tzdata                    2024b                hc8b5060_0    conda-forge
  ucrt                      10.0.22621.0         h57928b3_1    conda-forge
  vc                        14.3                h8a93ad2_22    conda-forge
  vc14_runtime              14.40.33810         hcc2c482_22    conda-forge
  vs2015_runtime            14.40.33810         h3bf8584_22    conda-forge
  wheel                     0.45.0             pyhd8ed1ab_0    conda-forge
  xz                        5.2.6                h8d14728_0    conda-forge
  zstd                      1.5.6                h0ea2cb4_0    conda-forge

@GabrielMarcilio
Copy link
Author

Hi Marcelo, i might be missing something here, hope you can give me some light:

When i create a conda env with only python, and then use pip to install cx_freeze and qt, the tutorial works fine
When i create a conda env with python, cx_freeze and qt the tutorial crashes when loading QtCore.

I compared the the environment variable PATH on both created executables:

import os
python_path = os.environ['PATH']

And it called my attention that the binary created from pip package contains the folders:

<executable_path>\lib\PyQt5\Qt5\bin #<- Qt5Core.dll is located here
<executable_path>\lib

While the binary created using conda package only contains the lib folder (it does not contains the bin folder where the Qt5Core is located)

<executable_path>\lib

(I am omitting other folders that are present in both binaries.)
I copied the contents from \lib\PyQt5\Qt5\bin into \lib, and then the binary created from conda package worked.

Do you have any idea why the paths are different when qt is created from pip or conda packages?

@marcelotduarte
Copy link
Owner

PyQt5 installed from pip has the modules an libraries in the same directory (libraries is in the PyQt5/lib) while the conda installation the directory structure is different. You can use an environment variable to check this.
In windows command line set QT_DEBUG=1 that cx_Freeze will print it to you.

@GabrielMarcilio
Copy link
Author

GabrielMarcilio commented Nov 19, 2024

Ok Marcelo i see that the pip and conda packages have some layout differences. To avoid this i decided to compare cx_freeze 6.15.12 (the version currently used by our project and in this version the tutorial works fine) and the cx_freeze 7.2.4 (the binary created from this version crashes in my machine when loading QtCore). Both versions uses the same pyqt conda package (5.15.19)

In version 6.15.12 the Qt5Core.pyd and Qt5Core_conda.dll are located in the same folder (\lib\PyQt5)
In version 7.2.4 the Qt5Core.pyd is inside lib\PyQt5 but the Qt5Core_conda.dll is inside \lib\PyQt5\Qt5\bin (this later folder is not in PATH)

From what i saw in code, the Qt5Core_conda.dll is copied to the bin folder because the function load_qt_qtcore inside _qthooks is using the library info (BinariesPath) to identify to where the files should be copied. and in my machine this is what is printed in the freeze output:

BinariesPath <env_path>\Library\bin -> lib\PyQt5\Qt5\bin

The change to copy the qt5Core_conda.dll to the bin folder is expected? If that is so how can the executable find the dll if that folder is not in the path? is it added with AddDllDirectory?

If this change is not expected i can test different freeze versions and check the version where the files stated to be copied to different folders.

Thanks

@marcelotduarte
Copy link
Owner

This is expected. Between 7.2.0 and 7.2.2 there are a series of fixes to solve duplicate files and files copied to wrong directories. One of these fixes is in #2578.
It is also expected that the search for the libraries (.dll) occurs based on an internal mechanism of Qt, as is in QLibraryInfo.

The PATH is not used to search the libraries, especially in Python 3.8+.

@GabrielMarcilio
Copy link
Author

Ok, if i add a call to os.add_dll_directory(<executable_path>\lib\PyQt5\Qt5\bin) then the example works fine.

I will continue debugging to find what is wrong in my machine / env.

Thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants