简体   繁体   中英

what's the matter with sublime text3 and python?

I got a problem when using sublime. I have several python's envs created by virtualenv,now I want to run my project with one of these env,so I built a new system with the settings below

{
    "cmd": ["E:/virtualenv_python36/Scripts/python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

but I got an exception when using this system

Traceback (most recent call last):
  File "C:\Users\kuo\Desktop\test.py", line 5, in <module>
    print(rps.read().decode())
UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 27237: illegal multibyte sequence
[Finished in 0.3s with exit code 1]
[cmd: ['E:/virtualenv_python36/Scripts/python.exe', '-u', 'C:\\Users\\kuo\\Desktop\\test.py']]
[dir: C:\Users\kuo\Desktop]
[path: C:\ProgramData\Oracle\Java\javapath;D:\Python36\Scripts\;D:\Python36\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\kuo\AppData\Local\Microsoft\WindowsApps;]

here is my test code

import urllib.request

rps = urllib.request.urlopen('http://www.baidu.com')
print(rps.read().decode())

It looks like the Python interpreter tries to load the result of your print invocation, which is a webpage in Chinese. Possibly it tries to show you the output.

I'm not sure the encoding of the page and the encoding of your file / buffer are the same. I'd rather use an explicit argument to .decode() .

(Also, consider using requests .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM