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 218 forks source link

Error while building Qt6 sample on MacOSX #2445

Closed tomneo2004 closed 1 month ago

tomneo2004 commented 5 months ago

Describe the bug An error occur while building application bundle on MacOSX for sample. copying /Users/phil/bob/Qt-opensource/6.7.1/macos/lib/libc++.1.dylib -> /Users/Nelson/Desktop/SmartTrainer/qt_app/build/exe.macosx-10.9-universal2-3.9/lib/libc++.1.dylib

error: [Errno 2] No such file or directory: '/Users/phil/bob/Qt-opensource/6.7.1/macos/lib/libc++.1.dylib'

and sometime it throw a different error

copying /Users/phil/bob/Qt-opensource/6.7.1/macos/lib/libSystem.B.dylib -> /Users/Nelson/Desktop/SmartTrainer/qt_app/build/exe.macosx-10.9-universal2-3.9/lib/libSystem.B.dylib

error: [Errno 2] No such file or directory: '/Users/phil/bob/Qt-opensource/6.7.1/macos/lib/libSystem.B.dylib'

To Reproduce

  1. Create a virtual environment(I use virtualenv) and activate environment.
  2. pip install PyQt6 cx_Freeze
  3. sudo python setup.py bdist_mac

Expected behavior Should have built without any error.

Desktop (please complete the following information):

How do I solve this issue?

marcelotduarte commented 5 months ago
  • OS architecture: ARM64 Intel

For universal2, only Python 3.11 and 3.12 are fully supported.

tomneo2004 commented 5 months ago
  • OS architecture: ARM64 Intel

For universal2, only Python 3.11 and 3.12 are fully supported.

I have tried install Python 3.11.5 and reinstall packages but still the same problem. And I don't know why it try to copy these files from this path /Users/phil/bob/Qt-opensource/6.7.1/macos/lib/ under /Users I don't have phil folder at all.

I use command to find these files sudo find / -name [XXX.dylib] all these files are under /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/

marcelotduarte commented 5 months ago

I have tested PyQt6 6.6.1 and 6.7.0 For me does not exist 6.7.1 yet in Pypi. image

tomneo2004 commented 5 months ago

I have tested PyQt6 6.6.1 and 6.7.0 For me does not exist 6.7.1 yet in Pypi. image

Try both PyQt6 6.7.0 and PyQt6 6.6.1 produce same errors. I am thinking do I need to install Qt opensource?

marcelotduarte commented 5 months ago

I can only access PyQt6 from Pypi, MinGW, and conda-forge to test. The hooks are based on and tested in these environments. Can you try it, and also, you can test cx_Freeze 7.0.

I don't have phil folder at all.

Phill is the maintainer of PyQt6 image

tomneo2004 commented 4 months ago

I can only access PyQt6 from Pypi, MinGW, and conda-forge to test. The hooks are based on and tested in these environments. Can you try it, and also, you can test cx_Freeze 7.0.

I don't have phil folder at all.

Phill is the maintainer of PyQt6 image

I still can't solve the problem by your suggestion. However I downgrade from PyQt6 to PyQt5 and everything working fine and application is running fine as well. Final conclusion I should stick with PyQt5. By the way on Window10 everything was fine without any issue.

Also I notice one problem not sure it is bug or intended while running the application. When I use python's os.path.getcwd() it return incorrect path on MacOS, it always return path /Users/[user-name] not current running program's directory. And to solve it I have to use os.path.dirname(sys.argv[0]).

marcelotduarte commented 4 months ago

Use os.path.dirname(sys.executable) Also, you can find this useful.

marcelotduarte commented 4 months ago

I can reproduce the error, with a slightly different message. error: [Errno 2] No such file or directory: '/Users/phil/bob/Qt-opensource/6.7.1/macos/lib/libobjc.A.dylib' pip list -v

  Python 3.11.9 (v3.11.9:de54cf5be3, Apr  2 2024, 07:12:50) [Clang 13.0.0 (clang-1300.0.29.30)]
  Package           Version     Location                                                                                         Installer
  ----------------- ----------- ------------------------------------------------------------------------------------------------ ---------
  cabarchive        0.2.4       /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  cx_Freeze         7.2.0.dev17 /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  filelock          3.15.1      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  pip               24.0        /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  PyQt6             6.7.0       /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  PyQt6-Qt6         6.7.1       /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  PyQt6-sip         13.6.0      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  setuptools        65.5.0      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  striprtf          0.0.26      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  typing_extensions 4.12.2      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  wheel             0.43.0      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip

The PyQt6-Qt6==6.7.1 was the origin of the error.

tomneo2004 commented 4 months ago

Use os.path.dirname(sys.executable) Also, you can find this useful.

It is fine for executable application but when you run application from python script within python virtual environment the path would point to python inside virtual environment folder which could lead to unexpected/incorrect path. This is not consistent while developing and deploying back and forth as I need to change code every time.

tomneo2004 commented 4 months ago

I can reproduce the error, with a slightly different message. error: [Errno 2] No such file or directory: '/Users/phil/bob/Qt-opensource/6.7.1/macos/lib/libobjc.A.dylib' pip list -v

  Python 3.11.9 (v3.11.9:de54cf5be3, Apr  2 2024, 07:12:50) [Clang 13.0.0 (clang-1300.0.29.30)]
  Package           Version     Location                                                                                         Installer
  ----------------- ----------- ------------------------------------------------------------------------------------------------ ---------
  cabarchive        0.2.4       /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  cx_Freeze         7.2.0.dev17 /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  filelock          3.15.1      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  pip               24.0        /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  PyQt6             6.7.0       /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  PyQt6-Qt6         6.7.1       /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  PyQt6-sip         13.6.0      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  setuptools        65.5.0      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  striprtf          0.0.26      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  typing_extensions 4.12.2      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip
  wheel             0.43.0      /Users/runner/.local/venv/cxfreeze_pyqt6_macosx-10.9-universal2_311/lib/python3.11/site-packages pip

The PyQt6-Qt6==6.7.1 was the origin of the error.

I tried PyQt6 6.7.0 and PyQt6 6.7.1 and produce errors from the one before or as same as yours. So does this means PyQt6 is not compatible?

marcelotduarte commented 4 months ago

As I said before: I have tested PyQt6 6.6.1 and 6.7.0 I'll test these versions next time. Also, try to fix PyQt6-Qt6 6.7.1 It is required that you observe that if you downgrade with the command: pip install PyQt6==6.6.1 and do a pip list you can check that PyQt6-Qt6 is 6.7.1 So a full downgrade is: pip install PyQt6==6.6.1 PyQt6-Qt6==6.6.1

tomneo2004 commented 4 months ago

As I said before: I have tested PyQt6 6.6.1 and 6.7.0 I'll test these versions next time. Also, try to fix PyQt6-Qt6 6.7.1 It is required that you observe that if you downgrade with the command: pip install PyQt6==6.6.1 and do a pip list you can check that PyQt6-Qt6 is 6.7.1 So a full downgrade is: pip install PyQt6==6.6.1 PyQt6-Qt6==6.6.1

Ok When you install PyQt6 and it will automatically install PyQt6-Qt6 the newest version. Newest version for PyQt6 is 6.7.0 but PyQt6-Qt6 is 6.7.1 and this later cause issue while building application. As you said downgrade with pip install PyQt6==6.6.1 PyQt6-Qt6==6.6.1 This does work and no issue. I also try pip install PyQt6==6.7.0 PyQt6-Qt6==6.7.0 no issue while building application.

I am facing new problem while running application. After I ran the application I got following error.

Traceback (most recent call last):
  File "/Users/Nelson/Desktop/test/.venv/lib/python3.11/site-packages/cx_Freeze/initscripts/__startup__.py", line 141, in run
    module_init.run(name + "__main__")
  File "/Users/Nelson/Desktop/test/.venv/lib/python3.11/site-packages/cx_Freeze/initscripts/console.py", line 25, in run
    exec(code, main_globals)
  File "test_pyqt6.py", line 5, in <module>
ImportError: dlopen(/Users/Nelson/Desktop/test/build/exe.macosx-10.9-universal2-3.11/lib/PyQt6/QtCore.abi3.so, 0x0002): Library not loaded: '@rpath/QtCore.framework/Versions/A/QtCore'
  Referenced from: '/Users/Nelson/Desktop/test/build/exe.macosx-10.9-universal2-3.11/lib/PyQt6/QtCore.abi3.so'
  Reason: tried: '/Users/Nelson/Desktop/test/build/exe.macosx-10.9-universal2-3.11/lib/PyQt6/Qt6/lib/QtCore.framework/Versions/A/QtCore' (no such file), '/Users/Nelson/Desktop/test/build/exe.macosx-10.9-universal2-3.11/lib/PyQt6/Qt6/lib/QtCore.framework/Versions/A/QtCore' (no such file), '/Users/Nelson/Desktop/test/build/exe.macosx-10.9-universal2-3.11/lib/QtCore.framework/Versions/A/QtCore' (no such file), '/Library/Frameworks/QtCore.framework/Versions/A/QtCore' (no such file), '/System/Library/Frameworks/QtCore.framework/Versions/A/QtCore' (no such file)
logout
Screen Shot 2024-06-17 at 10 44 32 am
marcelotduarte commented 3 months ago

Release 7.2.0 is out! Documentation

marcelotduarte commented 1 month ago

I made a test using:

  Package    Version
  ---------- -------
  cx-freeze  7.2.2
  pyqt6      6.7.1
  pyqt6-qt6  6.7.2
  pyqt6-sip  13.8.0

pyqt6-0-test_pyqt6-MacOS