Skip to contentSkip to conversation

prserv/serv: Avoid exception with newer versions of Python

master Peter Kjellerstedt 1 participant 1 message Jun 5, 2020

lore
Share & tools
lore
#0 lore raw

The following exception was received when doing devtool modify ...:

Exception: ModuleNotFoundError: No module named '_sysconfigdata'

This was previously partially solved in OE-Core, in commit 4b26eaf7 (prservice.py: fix do_package with newer Python in Ubuntu 20.04). However, that only solved the problem for some cases where prserv was imported. This should solve if for all of them.

---
 bitbake/lib/prserv/serv.py | 6 ++++++
 1 file changed, 6 insertions(+)
bitbake/lib/prserv/serv.py +6 -0
index 25dcf8a0ee..48f4b5b05d 100644
@@ -2,6 +2,12 @@
 # SPDX-License-Identifier: GPL-2.0-only
 #
 
+# Make sure _PYTHON_SYSCONFIGDATA_NAME is not set in the environment, which may
+# happen for recipes that, e.g., inherit python3native, which sets it. Otherwise
+# importing from xmlrpc.server fails with "No module named '_sysconfigdata'"
+if '_PYTHON_SYSCONFIGDATA_NAME' in os.environ:
+    del os.environ['_PYTHON_SYSCONFIGDATA_NAME']
+
 import os,sys,logging
 import signal, time
 from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler