Skip to content

Conversation

@dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Sep 4, 2024

If performing a cmake build with Python 3.11 or earlier, everything works fine; however, if using Python 3.12 the cmake build fails with ModuleNotFoundError: No module named 'distutils'. This is because the distutils module was deleted in Python 3.12 (see https://peps.python.org/pep-0632/ and https://docs.python.org/3/whatsnew/3.12.html#distutils).

The problem was coming from nanopb which referenced the distutils module in its CMakeLists.txt. The fix was to copy the replacement command that works in Python 3.12, and should work all the way back to Python 3.7 (see nanopb/nanopb#727 and nanopb/nanopb#730). This PR merely tweaks the patching that is already done on nanopb.

Here is what the error looks like, which this PR fixes:

$ PATH="$HOME/.pyenv/versions/3.12.3/bin/python:$PATH" cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -GNinja
...
-- Found PythonInterp: /home/linuxbrew/.linuxbrew/bin/python3 (found suitable version "3.12.3", minimum required is "3.7") 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'distutils'
CMake Error at build/external/src/nanopb/CMakeLists.txt:61 (install):
  install FILES given no DESTINATION!


CMake Error at build/external/src/nanopb/CMakeLists.txt:61 (install):
  install FILES given no DESTINATION!


-- Found Python3: /home/linuxbrew/.linuxbrew/bin/python3.12 (found version "3.12.3") found components: Interpreter 
-- FirebaseSetupPythonInterpreter(FirestoreProtos): Creating Python virtualenv in firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos using /home/linuxbrew/.linuxbrew/bin/python3.12
-- firebase_execute_process(): running command: /home/linuxbrew/.linuxbrew/bin/python3.12 -m venv firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos
-- FirebaseSetupPythonInterpreter(FirestoreProtos): Found Python executable in virtualenv: firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos/bin/python3
-- FirebaseSetupPythonInterpreter(FirestoreProtos): Installing Python dependencies into firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos: six
-- firebase_execute_process(): running command: firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos/bin/python3 -m pip install six
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six
Successfully installed six-1.16.0

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: python3 -m pip install --upgrade pip
-- FirebaseSetupPythonInterpreter(FirestoreCore): Creating Python virtualenv in firebase-ios-sdk/build/Firestore/core/pyvenv/FirestoreCore using /home/linuxbrew/.linuxbrew/bin/python3.12
-- firebase_execute_process(): running command: /home/linuxbrew/.linuxbrew/bin/python3.12 -m venv firebase-ios-sdk/build/Firestore/core/pyvenv/FirestoreCore
-- FirebaseSetupPythonInterpreter(FirestoreCore): Found Python executable in virtualenv: firebase-ios-sdk/build/Firestore/core/pyvenv/FirestoreCore/bin/python3
-- Looking for dispatch_async_f
-- Looking for dispatch_async_f - not found
-- Looking for arc4random
-- Looking for arc4random - found
-- Looking for include file openssl/rand.h
-- Looking for include file openssl/rand.h - found
-- Configuring incomplete, errors occurred!

#no-changelog

@dconeybe dconeybe self-assigned this Sep 4, 2024
@dconeybe dconeybe changed the title Fix cmake build with Python 3.12, which deleted the long-deprecated 'distutils' module Fix cmake builds with Python 3.12, which deleted the long-deprecated 'distutils' module Sep 4, 2024
@dconeybe dconeybe requested a review from ehsannas September 4, 2024 17:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants