Message329050
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. |
|
Date |
User |
Action |
Args |
2018-11-01 09:56:37 | Valentin Zhao | set | recipients:
+ Valentin Zhao |
2018-11-01 09:56:37 | Valentin Zhao | set | messageid: <1541066197.73.0.788709270274.issue35131@psf.upfronthosting.co.za> |
2018-11-01 09:56:37 | Valentin Zhao | link | issue35131 messages |
2018-11-01 09:56:37 | Valentin Zhao | create | |
|