Sublime Text 3打开文件中文乱码问题解决

Sublime Text 3在刚安装完成的时候,打开包含中文的txt文件会出现乱码问题
中文乱码问题
下面介绍解决该问题的方法:

1.通过快捷键 ctrl + ~ 进入命令行,并输入以下命令然后回车
import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)


上述命令可能会报以下错误

Traceback (most recent call last):
  File "./python3.3/urllib/request.py", line 1248, in do_open
  File "./python3.3/http/client.py", line 1065, in request
  File "./python3.3/http/client.py", line 1103, in _send_request
  File "./python3.3/http/client.py", line 1061, in endheaders
  File "./python3.3/http/client.py", line 906, in _send_output
  File "./python3.3/http/client.py", line 844, in send
  File "./python3.3/http/client.py", line 822, in connect
  File "./python3.3/socket.py", line 435, in create_connection
  File "./python3.3/socket.py", line 426, in create_connection
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "./python3.3/urllib/request.py", line 156, in urlopen
  File "./python3.3/urllib/request.py", line 469, in open
  File "./python3.3/urllib/request.py", line 487, in _open
  File "./python3.3/urllib/request.py", line 447, in _call_chain
  File "./python3.3/urllib/request.py", line 1274, in http_open
  File "./python3.3/urllib/request.py", line 1251, in do_open
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>

这是由于网络访问网站http://packagecontrol.io/无法访问成功导致的,所以确保能够访问该网址时才能继续安装,这里我直接通过科学上网的方式就可以访问了,但是又出现了下面的问题:

>>> import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
Error validating download (got 6f4c264a24d933ce70df5dedcf1dcaeeebe013ee18cced0ef93d5f746d80ef60 instead of 7183a2d3e96f11eeadd761d777e62404e330c659d4bb41d3bdf022e94cab3cd0), please try manual install

根据报错信息将该命令中的7183a2d3e96f11eeadd761d777e62404e330c659d4bb41d3bdf022e94cab3cd0 字符串换成6f4c264a24d933ce70df5dedcf1dcaeeebe013ee18cced0ef93d5f746d80ef60再重试即可发现成功

重启Sublime Text 3之后进行下一步

2.安装ConvertToUTF8。

通过快捷键 Ctrl + shift + P,然后在弹出的输入框输入 install,选择Package Control:install Package回车

在出现的插件命令行搜索ConvertToUTF8,选中回车进行插件安装

插件安装成功后会出现以下信息
插件安装成功截图
重启Sublime Text 3后再次打开之前中文乱码的文件发现,中文能够正常显示

猜你喜欢

转载自blog.csdn.net/weixin_44247225/article/details/87163265