This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Valentin Zhao
Recipients Valentin Zhao
Date 2018-11-01.09:56:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541066197.73.0.788709270274.issue35131@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-11-01 09:56:37Valentin Zhaosetrecipients: + Valentin Zhao
2018-11-01 09:56:37Valentin Zhaosetmessageid: <1541066197.73.0.788709270274.issue35131@psf.upfronthosting.co.za>
2018-11-01 09:56:37Valentin Zhaolinkissue35131 messages
2018-11-01 09:56:37Valentin Zhaocreate