windows7使用sublime Text3作为python的IDE(一)

一、下载安装sublime text3二、下载python-2.7的安装包(安装的时候有个选项,是否写入环境变量,记得勾选.).三、安装完python以后,在电脑->右键->属性->高级系统设置->环境变量->Path环境变量是否包含了python的安装目录,如果没有请你手工设置进去.四、测试python环境变量是否安装好.ctrl+r调出运行窗口.直接输入python,看看是否能够进入python命令行模式.如果不行,尝试输入python.exe.还是不行那么就有问题了. 尝试检查环境变量,或者直接运行python安装目录中的python或者python.exe程序.看看是否正确安装,是在不行,建议重启一下机器(windows万能药)试试.五、打开sublime,创建一个test.py文件,在文件中输入

a = "this is a test variables"print "tester is say: %s" % a

然后ctrl+b运行,如果报错.

[Decode error - output not utf-8][Finished in 2.4s with exit code 1][shell_cmd: python -u "C:\Users\andy\Downloads\mysql-utilities-1.5.2\test_a.py"][dir: C:\Users\andy\Downloads\mysql-utilities-1.5.2][path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\link;C:\Program Files\TortoiseSVN\bin;D:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Bitvise SSH Client]

如果是上面的错误,那么证明你还不是字符集的问题,而是python解析器还没有定位到.你可以通过path看,里面没有你python的位置.我这里在cmd里面可以成功运行python -u “C:\Users\andy\Downloads\mysql-utilities-1.5.2\test_a.py”,环境变量是OK的.我重启了一下sublime就可以了.现在已经可以执行ASCII的命令了.

然后调试中文:

a = "this is a test variables中文"print "tester is say: %s" % a

ctrl+b执行.

File "C:\Users\andy\Downloads\mysql-utilities-1.5.2\test_a.py", line 2SyntaxError: Non-ASCII character '\xe4' in file C:\Users\andy\Downloads\mysql-utilities-1.5.2\test_a.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details[Finished in 0.6s with exit code 1][shell_cmd: python -u "C:\Users\andy\Downloads\mysql-utilities-1.5.2\test_a.py"][dir: C:\Users\andy\Downloads\mysql-utilities-1.5.2][path: D:\Python27\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\link;C:\Program Files\TortoiseSVN\bin;D:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Bitvise SSH Client]

这次就真是字符集问题了.处理方法:1、在文件开头加上

#coding: utf-8 or # -*- coding: utf-8 -*-a = "this is a test variables 中文"print "tester is say: %s" % a

这里注意了,如果你的中文是之前输入的,那么你需要把之前输入的中文删掉,从新输入,不然之前的中文还是ASCII的.

2、如果上面方法不奏效,使用下面方法打开sublime的导航栏Tools->build system->New build system,然后输入下面的内容,文件名保存为Python.sublime-build,然后重启sublime试试看,最好重新创建文件,先写coding: utf-8,然后再写中文.

{"shell_cmd": ["Python","-u","$file"],"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)","selector": "source.python","encoding": "cp936"}
windows7使用sublime Text3作为python的IDE(一)

相关文章:

你感兴趣的文章:

标签云: