简体   繁体   English

sublime text3和python有什么关系?

[英]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 我有几个由virtualenv创建的python env,现在我想使用其中一个env运行我的项目,因此我使用以下设置构建了一个新系统

{
    "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. 看起来Python解释器试图加载您的print调用结果 ,这是中文网页。 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() . 我宁愿对.decode()使用显式参数。

(Also, consider using requests .) (另外,请考虑使用requests 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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