Work around missing Py_GetArgcArgv in win Py38 launcher,
@@ -45,7 +45,7 @@ report_time("After defining report_time")
import logging
import os.path
-from typing import TYPE_CHECKING, Optional, cast
+from typing import TYPE_CHECKING, Optional, cast, List
SINGLE_INSTANCE_DEFAULT = True
BACKEND_LOG_MARKER = "Thonny's backend.log"
@@ -392,7 +392,7 @@ def get_frontend_log_file():
return os.path.join(THONNY_USER_DIR, "frontend.log")
-def get_orig_argv():
+def _get_orig_argv() -> Optional[List[str]]:
try:
from sys import orig_argv # since 3.10
@@ -403,7 +403,13 @@ def get_orig_argv():
argc = ctypes.c_int()
argv = ctypes.POINTER(ctypes.c_wchar_p if sys.version_info >= (3,) else ctypes.c_char_p)()
+ try:
ctypes.pythonapi.Py_GetArgcArgv(ctypes.byref(argc), ctypes.byref(argv))
+ except AttributeError:
+ # See https://github.com/thonny/thonny/issues/2206
+ # and https://bugs.python.org/issue40910
+ # This symbol is not available in thonny.exe built agains Python 3.8
+ return None
# Ctypes are weird. They can't be used in list comprehensions, you can't use `in` with them, and you can't
# use a for-each loop on them. We have to do an old-school for-i loop.
@@ -442,7 +448,7 @@ def _configure_logging(log_file, console_level=None):
# Log most important info as soon as possible
main_logger.info("Thonny version: %s", get_version())
main_logger.info("cwd: %s", os.getcwd())
- main_logger.info("original argv: %s", get_orig_argv())
+ main_logger.info("original argv: %s", _get_orig_argv())
main_logger.info("sys.executable: %s", sys.executable)
main_logger.info("sys.argv: %s", sys.argv)
main_logger.info("sys.path: %s", sys.path)
