-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The value of Py_SetPath is not used to populate the configuration #82415
Comments
When calling Py_SetPath(), the value that is passed in is ignored. |
It's a 3.8 regression: I set the priority to release blocker. |
A very simple way to reproduce the bug: Using pyInstaller, after applying these patches (to fix other Python3.8 issues) pyinstaller/pyinstaller#4441 you will get Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding This is because Python will use the default value for sys.path, including the "lib" subdirectory: /dist/hello/lib/python3.8 Instead, that value should be the one that pyinstaller passes when calling Py_SetPath() here: https://github.com/pyinstaller/pyinstaller/blob/develop/bootloader/src/pyi_pythonlib.c#L495 So it should be: /dist/hello/python3.8 |
That's a regression that I introduced between Python 3.7 and 3.8 when refactoring _PyCoreConfig/_PyPathConfig code into PyConfig/_PyPathConfig. Previously, if Py_SetPath() was called, the specified string was used to fill config->module_search_paths. Now, this string is basically ignored. PR 16298 fix this regression. |
I created bpo-38236 "Dump the Python path configuration at the first import error" which should ease to debug such issues. |
I fixed this regression. Thanks for the bug report. |
Why are we keeping the DLL path around at all? It should only be being used in 1-2 places during path calculation. |
Steve:
_PyPathConfig_Init() initializes _Py_dll_path global variable which is only used by _Py_CheckPython3(). _Py_CheckPython3() is called at each _PyImport_FindSharedFuncptrWindows() call which is used by _PyImport_LoadDynamicModuleWithSpec() (to import a .pyd extension). I tried to minimize my changes to fix the issue, I tried to leave _Py_CheckPython3() unchanged. But I made one change in _Py_CheckPython3(): it handles the case _Py_dll_path=NULL... which should never occur, but I wasn't 100% sure that it really can never occur. Python 3.6 (before my init work), _Py_CheckPython3() used "static wchar_t dllpath[MAXPATHLEN+1];": it was less important when dllpath is initialized. -- _PyPathConfig_Calculate() of PC/getpathp.c now uses a temporary variable which stores the result of _Py_GetDLLPath(). |
Ah okay, maybe I'll take the time later on (in a separate issue) to get rid of it fully. We may as well load python3.dll at startup anyway, it's not expensive. |
Hum, in fact the bug was even worse: Py_SetPythonHome() and Py_SetProgramName() calls are also ignored. I'm not sure when I introduced these regressions. PR 16335 fix this bug as well. |
The new tests fail on macOS. x86-64 High Sierra 3.x: ====================================================================== Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib/test/test_embed.py", line 1130, in test_init_pybuilddir
self.check_all_configs("test_init_compat_config", config,
File "/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib/test/test_embed.py", line 681, in check_all_configs
self.check_config(configs, expected_config)
File "/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib/test/test_embed.py", line 613, in check_config
self.assertEqual(config, expected)
AssertionError: {'_co[655 chars]ne, 'module_search_paths': ['/Users/buildbot/b[1407 chars]': 1} != {'_co[655 chars]ne, 'executable': '/var/folders/sy/9hwmqyx14s1[1383 chars]': 1}
{'_config_init': 1,
'_init_main': 1,
'_install_importlib': 1,
'argv': [''],
'base_exec_prefix': '/Users/buildbot/buildarea/3.x.billenstein-sierra/build/target',
- 'base_executable': '/private/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmp2a98rb5k/_testembed',
? + 'base_executable': '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmp2a98rb5k/_testembed',
'base_prefix': '/Users/buildbot/buildarea/3.x.billenstein-sierra/build/target',
'buffered_stdio': 1,
'bytes_warning': 0,
'check_hash_pycs_mode': 'default',
'configure_c_stdio': 0,
'dev_mode': 0,
'dump_refs': 0,
'exec_prefix': '/Users/buildbot/buildarea/3.x.billenstein-sierra/build/target',
- 'executable': '/private/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmp2a98rb5k/_testembed',
? --------
+ 'executable': '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmp2a98rb5k/_testembed',
'faulthandler': 0,
'hash_seed': 0,
'home': None,
'import_time': 0,
'inspect': 0,
'install_signal_handlers': 1,
'interactive': 0,
'isolated': 0,
'malloc_stats': 0,
'module_search_paths': ['/Users/buildbot/buildarea/3.x.billenstein-sierra/build/target/lib/python39.zip',
'/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib',
'/Users/buildbot/buildarea/3.x.billenstein-sierra/build/build/lib.macosx-10.13-x86_64-3.9-pydebug',
'/Users/buildbot/buildarea/3.x.billenstein-sierra/build/target/lib/python39.zip',
'/Users/buildbot/buildarea/3.x.billenstein-sierra/build/target/lib/python3.9',
- '/private/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmp2a98rb5k/libdir'],
? + '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmp2a98rb5k/libdir'], ====================================================================== Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib/test/test_embed.py", line 1182, in test_init_pyvenv_cfg
self.check_all_configs("test_init_compat_config", config,
File "/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib/test/test_embed.py", line 681, in check_all_configs
self.check_config(configs, expected_config)
File "/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib/test/test_embed.py", line 613, in check_config
self.assertEqual(config, expected)
AssertionError: {'_co[655 chars]ne, 'module_search_paths': ['/Users/buildbot/b[1416 chars]': 1} != {'_co[655 chars]ne, 'executable': '/var/folders/sy/9hwmqyx14s1[1400 chars]': 1}
{'_config_init': 1,
'_init_main': 1,
'_install_importlib': 1,
'argv': [''],
'base_exec_prefix': '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmprrz3csek',
- 'base_executable': '/private/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpczgnz4r3/_testembed',
? + 'base_executable': '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpczgnz4r3/_testembed',
'base_prefix': '/Users/buildbot/buildarea/3.x.billenstein-sierra/build/target',
'buffered_stdio': 1,
'bytes_warning': 0,
'check_hash_pycs_mode': 'default',
'configure_c_stdio': 0,
'dev_mode': 0,
'dump_refs': 0,
'exec_prefix': '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmprrz3csek',
- 'executable': '/private/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpczgnz4r3/_testembed',
? + 'executable': '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpczgnz4r3/_testembed', |
And on FreeBSD. AMD64 FreeBSD CURRENT Shared 3.x: ====================================================================== Traceback (most recent call last):
File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_embed.py", line 1130, in test_init_pybuilddir
self.check_all_configs("test_init_compat_config", config,
File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_embed.py", line 681, in check_all_configs
self.check_config(configs, expected_config)
File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_embed.py", line 613, in check_config
self.assertEqual(config, expected)
AssertionError: {'_co[671 chars]ne, 'module_search_paths': ['/usr/home/buildbo[1297 chars]': 1} != {'_co[671 chars]ne, 'executable': '/tmp/tmpsa4mgwz2/_testembed[1285 chars]': 1}
{'_config_init': 1,
'_init_main': 1,
'_install_importlib': 1,
'argv': [''],
'base_exec_prefix': '/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/target',
- 'base_executable': '/var/tmp/tmpsa4mgwz2/_testembed',
? + 'base_executable': '/tmp/tmpsa4mgwz2/_testembed',
'base_prefix': '/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/target',
'buffered_stdio': 1,
'bytes_warning': 0,
'check_hash_pycs_mode': 'default',
'configure_c_stdio': 0,
'dev_mode': 0,
'dump_refs': 0,
'exec_prefix': '/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/target',
- 'executable': '/var/tmp/tmpsa4mgwz2/_testembed',
? ----
+ 'executable': '/tmp/tmpsa4mgwz2/_testembed',
'faulthandler': 0,
'hash_seed': 0,
'home': None,
'import_time': 0,
'inspect': 0,
'install_signal_handlers': 1,
'interactive': 0,
'isolated': 0,
'malloc_stats': 0,
'module_search_paths': ['/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/target/lib/python39.zip',
'/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib',
'/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/build/lib.freebsd-13.0-CURRENT-amd64-3.9-pydebug',
'/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/target/lib/python39.zip',
'/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/target/lib/python3.9',
- '/var/tmp/tmpsa4mgwz2/libdir'],
? + '/tmp/tmpsa4mgwz2/libdir'], ====================================================================== Traceback (most recent call last):
File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_embed.py", line 1182, in test_init_pyvenv_cfg
self.check_all_configs("test_init_compat_config", config,
File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_embed.py", line 681, in check_all_configs
self.check_config(configs, expected_config)
File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_embed.py", line 613, in check_config
self.assertEqual(config, expected)
AssertionError: {'_co[671 chars]ne, 'module_search_paths': ['/usr/home/buildbo[1216 chars]': 1} != {'_co[671 chars]ne, 'executable': '/tmp/tmpszvtbyq4/_testembed[1208 chars]': 1}
{'_config_init': 1,
'_init_main': 1,
'_install_importlib': 1,
'argv': [''],
'base_exec_prefix': '/tmp/tmpr0gyjdqs',
- 'base_executable': '/var/tmp/tmpszvtbyq4/_testembed',
? + 'base_executable': '/tmp/tmpszvtbyq4/_testembed',
'base_prefix': '/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/target',
'buffered_stdio': 1,
'bytes_warning': 0,
'check_hash_pycs_mode': 'default',
'configure_c_stdio': 0,
'dev_mode': 0,
'dump_refs': 0,
'exec_prefix': '/tmp/tmpr0gyjdqs',
- 'executable': '/var/tmp/tmpszvtbyq4/_testembed',
? + 'executable': '/tmp/tmpszvtbyq4/_testembed', |
Oh, there is a regression: vstinner@apu$ ./python
Python 3.9.0a0 (heads/master:88feaecd46, Sep 26 2019, 03:26:37)
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _tkinter
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] PyInit__tkinter() calls Py_GetProgramName(). But Python initialization no longer copies PyConfig path configuration into _Py_path_info (the global configuration). So Python has to recompute the path configuration which logs 3 warnings. |
It's fixed by commit 12f2f17 which adds new tests to prevent any regression. |
Oh, the main issue has been fixed and I added a lot of tests. So I remove the "release blocker" priority. I would like to keep the issue open since I plan to do one more change: use PyWideStringList in _PyPathConfig for module_search_paths to support paths which contains DELIM (":" on Unix). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: