[Python] Sublime Text: set a build on Python 2.7 creating a sublime-build file (solution to WinError 2 problem)
- Get link
- X
- Other Apps
If anyone attempts to install Sublime Text, faces an error message [WinError 2], and notices your Python code does not work (like I did), I suggest you to do the following:
(note: I am working this on Windows 10)
Situation: error message on my computer when I run "Build" by pressing ctrl+B
1. Make sure your Python code is saved (e.g. I saved my HelloWorld.py file on my C:\Brian\PythonLab)
2. Go to Tools > Build System > New Build System
3. on the untitled.sublime-build, type the following
{
"cmd": ["(your directory for Python goes here)", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
In my case, I installed Python 2.7 on the directory C:\python27
Note that the directory should be represented using double \ (\\).
That is,
C:\\Python27\\python.exe
So in my case:
{
"cmd": ["C:\\Python27\\python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
should be the appropriate address for python.exe on my computer.
4. save the sublime-build file: make sure the file extension must be .sublime-build
In my case, I typed "Python27.sublime-build" and saved.
Note: make sure you save on:
C:\Users\[username]\AppData\Roaming\Sublime Text\Packages\User
In my case, it would be:
C:\Users\bjhle\AppData\Roaming\Sublime Text\Packages\User
5. Go to Tools > Build System > Python27 (depending on the name you saved)
6. Go to your "py" code tab > tools > build with > choose your Python (in my case Python27)
7. Run "Build," using Tools > Build or pressing Ctrl+B
8. Result on my Sublime Text:
- Get link
- X
- Other Apps
Comments
Post a Comment