Bug 439092 - Python scripts do not work properly when Python 2 is installed (alongside Python 3)
Summary: Python scripts do not work properly when Python 2 is installed (alongside Pyt...
Status: REPORTED
Alias: None
Product: extra-cmake-modules
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: ecm-bugs-null@kde.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-24 02:33 UTC by Max Pastushkov
Modified: 2021-08-31 22:28 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Max Pastushkov 2021-06-24 02:33:22 UTC
SUMMARY

When something that requires ECM is compiled, some scripts like "find-modules/run-sip.py" run in Python 2 instead of 3, causing an error.

STEPS TO REPRODUCE
1. Install Python 2 and 3
2. Compile any package that uses ECM, for example, "ki18n-git"
3. If the python2 symbolic link is removed, compilation is successful

OBSERVED RESULT
Traceback (most recent call last):
  File "/usr/share/ECM/find-modules/run-sip.py", line 10, in <module>
    from PyQt5.Qt import PYQT_CONFIGURATION
ImportError: No module named PyQt5.Qt

EXPECTED RESULT
Successful compilation

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 5.12.12-arch1-1
(available in About System)
KDE Plasma Version: 5.22.2
KDE Frameworks Version: 5.84.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
On Arch, the PyQt5 library can only be installed for Python 3 and not 2, so the script fails to find the library since it is being run on Python 2. If the python2 symbolic link is removed, the cmake installer no longer detects Python 2 and the script is run with Python 3.

This should be changed so the cmake file, "find-modules/FindPythonModuleGeneration.cmake", forces Python 3.
Comment 1 nyanpasu64 2021-08-31 22:28:02 UTC
The code in question is at https://invent.kde.org/frameworks/extra-cmake-modules/-/blob/3a75f891f5a914280a2a23194d1a61b19387d8ae/find-modules/FindPythonModuleGeneration.cmake#L258.

`foreach (pyversion "2" "3")` searches for a working Python, checking Python 2 first, then 3. It does so using:

  execute_process(
    COMMAND ${GPB_PYTHON_COMMAND} ${CMAKE_CURRENT_LIST_DIR}/sip_generator.py --self-check ${libclang_LIBRARY}
    RESULT_VARIABLE selfCheckErrors
    ERROR_QUIET
  )

The problem is that this command completes successfully on Python 2 (either that, or CMake thinks it does), so GPB_PYTHON_COMMAND is set to GPB_PYTHON2_COMMAND. But calling GPB_PYTHON2_COMMAND run-sip.py fails later on.

One solution is to change sip_generator.py to run `from PyQt5.Qt import PYQT_CONFIGURATION` like run-sip.py does, to test for errors more thoroughly. I think it's also a good idea to test Python 3 before Python 2, or possibly remove Python 2 entirely.