[issue35131] Cannot access to customized paths within .pth file
Valentin Zhao
report at bugs.python.org
Thu Nov 1 05:56:37 EDT 2018
New submission from Valentin Zhao <jmsqzzl at gmail.com>:
I want to manage all the packages that I installed so every time adding package I set "--target" so the package will be downloaded there. Then I wrote the directory in a .pth file which is located in "/Python36/Lib/site-packages" so I could still get accessed to all the packages even though they are not located within "Python36" folder.
However, my current user name of Windows is a Chinese name, which means the customized path I mentioned before has Chinese characters within it, thus the .pth file will be also encoded with 'gbk'. Every time I would like to import these packages will get "UnicodeDecodeError: 'gbk' can't decode byte xxx...".
Fortunately I have found the reason and cracked the problem: python read .pth files without setting any encoding. The code is located in "Python36/Lib/site.py"
def addpackage(sitedir, name, known_paths):
if known_paths is None:
known_paths = _init_pathinfo()
reset = True
else:
reset = False
fullname = os.path.join(sitedir, name)
try:
# here should set the second param as encoding='utf-8'
f = open(fullname, "r")
except OSError:
return
# other codes
And after I doing this, everything goes well.
----------
components: Library (Lib)
files: IMG_20181101_173328_[B at ae031df.jpg
messages: 329050
nosy: Valentin Zhao
priority: normal
severity: normal
status: open
title: Cannot access to customized paths within .pth file
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file47899/IMG_20181101_173328_[B@ae031df.jpg
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35131>
_______________________________________
More information about the Python-bugs-list
mailing list