STINNER Victor <victor.stin...@haypocalc.com> added the comment:

This issue remembers me the issue #6612 (failure if the current directory was 
removed): the fix was to ignore os.getcwd().

Attached patch ignores os.path.expanduser() error (KeyError) and keeps ~ in the 
path. Example without HOME var and with an non existent user (uid 12345):

----------------------
$ env -i ./python
>>> import sysconfig
>>> sysconfig.get_config_var('userbase')
'~/.local'

>>> sysconfig.get_paths(scheme='posix_user', expand=False)
{'platstdlib': '{userbase}/lib/python{py_version_short}', 'platlib': 
'{userbase}/lib/python{py_version_short}/site-packages', 'purelib': 
'{userbase}/lib/python{py_version_short}/site-packages', 'stdlib': 
'{userbase}/lib/python{py_version_short}', 'scripts': '{userbase}/bin', 
'include': '{userbase}/include/python{py_version_short}', 'data': '{userbase}'}

>>> sysconfig.get_paths(scheme='posix_user')              
{'platstdlib': '~/.local/lib/python3.3', 'platlib': 
'~/.local/lib/python3.3/site-packages', 'purelib': 
'~/.local/lib/python3.3/site-packages', 'stdlib': '~/.local/lib/python3.3', 
'scripts': '~/.local/bin', 'include': '~/.local/include/python3.3', 'data': 
'~/.local'}
----------------------

Example with an existant user but without HOME var:
----------------------
marge$ env -i ./python
>>> import sysconfig
>>> sysconfig.get_config_var('userbase')
'/home/haypo/.local'
>>> sysconfig.get_paths(scheme='posix_user')      
{'platstdlib': '/home/haypo/.local/lib/python3.3', 'platlib': 
'/home/haypo/.local/lib/python3.3/site-packages', 'purelib': 
'/home/haypo/.local/lib/python3.3/site-packages', 'stdlib': 
'/home/haypo/.local/lib/python3.3', 'scripts': '/home/haypo/.local/bin', 
'include': '/home/haypo/.local/include/python3.3', 'data': '/home/haypo/.local'}
----------------------

----------
nosy: +tarek
title: "import site failed" when Python can't find home directory -> "import 
site failed" when Python can't find home directory (sysconfig._getuserbase)

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10496>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to