Sublime Text 2 Build Python environment recurring error

Source: Internet
Author: User
Tags python script sublime text



Sublime Text 2 Under the Python environment, the most likely error is the Python environment configuration error, resulting in build (CTRL+B) no response.



The configuration of the Python programming environment is easy to find on the web. First, you have installed the Python compilation environment on Windows, and the necessary plugins have been installed in sublime text 2. Below we directly configure Python, allowing Python code to run merrily in Sublime Text 2. The common configuration is mainly two kinds.



A system variable, such as PATH:C:\PYTHON34, that sets environment variables in the Windows Advanced system settings. After setting the system environment variables, run cmd, enter Python and return to see if there is a Python version information input. If none is set to fail or the installation of Python is unsuccessful.



Second, start sublime Text 2,preferences->browse Packages Open the \python\python.sublime-build file, change the configuration inside to:


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


The above two scenarios of configuring Python compiler path, only need to use one on the line, if the version of Python installed more, we recommend the use of a second scenario, easy to change. After setting the Python compiler path, open the sublime Text 2 menu Tools->build System Check automatic or Python. Load a simple Python script in sublime Text 2, or CTRL + N to create a new file, enter the code (here is the Python3.4 version, if it is version 2.7 or older, the print function does not need brackets ()):


Print ("Hi, Sublime Text 2")


Save to non-Chinese path, if saved to the Chinese path, will prompt compilation failure, be sure to note. Tools->build or Ctrl+b, perform the compilation. If the compilation is successful, you are lucky to not be too disappointed if the compilation is unsuccessful or if nothing happens after the ctrl+b. Ctrl+~ look at the compilation errors, if there are errors below, you need to change a bit of code


File ".\sublime_plugin.py", line 337, in run_
File ".\exec.py", line 154, in run
File ".\exec.py", line 48, in __init__
UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 13-16: ordinal not in range(128)


Locate exec.py under the Sublime Text 2 profile directory (c:\%appdata%\sublime text 2\packages\default), and then locate the 第41-42 line:


For K, V in Proc_env.iteritems ():        proc_env[k] = Os.path.expandvars (v). Encode (sys.getfilesystemencoding ())    


Plus an exception handling


    try:
            for k, v in proc_env.iteritems():
                proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())
        except UnicodeDecodeError:
            print "Encoding error..."





Many people on the network asked sublime Text 2 ctrl+b to perform the compilation why did not respond. Are basically pits in the above steps. 1, the Python compiler path is not well, 2, build system compiler language configuration error, 3, the script is saved in the Chinese path, 4, Sublime Text 2 in the configuration file encoding error.



Sublime Text 2 Build Python environment recurring error


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.