Sublime Run Python 3
- Run Python In Sublime Text 3 Mac
- Sublime Text 3 Python Setup
- Use Sublime Text With Python
- Sublime Text Run Python 3
Step 1: Download and install Python3 and Sublime text
- The second part of this series shows you how to run Python 3.x scripts within Sublime Text 3. But before you begin, Sublime needs to know where you’ve installed Python! Go here: C:%AppData% Sublime Text 3 Packages User (a) Create a file called Python3x.sublime-build.
- But Sublime uses path /usr/bin/python when building python source. I strongly suggest you to roll back the alias definition. Now to build your code using python3, you can either install python-is-python3 package which is available on 20.04 and higher to invoke python3 using python or create a new build system and set that build system as default.
Sublime Text 3 will run your python code inside the integrated console when you use Ctrl + B if you want to run your code at own terminal, but still get some error information inside to integrated console, you. One way: https://github.com/Wilhox/Integrated-builder.git.
You can download Python3 from this page https://www.python.org/downloads/ and install it by following simple wizard steps.
The latest version of Sublime Text can be downloaded from this page https://www.sublimetext.com/download. Install it on your computer and follow the next step.
Run Python In Sublime Text 3 Mac
Note: At the time of writing this post, the Sublime Text 3 was the latest version available.
Step 2: Find the Python3 path
For Windows, open cmd and type the following command.
Sublime Text 3 Python Setup
The output will show you the version of the Python installed on your computer. In my case, it was Python 3.7.4
This will also start the Python console which help us to find the path of the python installed. Now, type the following commands.
The output will give the desired path. Save this somewhere on notepad.
For Unix or Mac, open terminal and type the following command.
The output will give the path that you are looking for. Save this somewhere to use in next step.
Step 3: Setup Build System for Python 3 on Sublime Text
Sublime ships with some pre-defined build systems, but in our case, we are going to build a custom build system to run Python3 programs.
- Open Sublime, go to Tools > Build System > New Build System.
- A new file will open with some default code in it. You can delete everything on this file and copy-paste this code.
For Windows,Note: Get the path you saved and replace the double backward slashes with forward slash and place it in above location. This is important because the Sublime will not understand the path with backward slashes therefore it is necessary to make this change. Most importantly, also add /python.exe at the end of the path.
For Mac, use the path you saved.
Now, save the above file with name like Python-37.sublime-build.
Step 4: Select new Build System and run the code
- Select your new build system by going to Tools > Build System > Python-37.
- Create a new file, add the following code to test and save the file with .py extension
- Run the code by Ctrl + B for Window users and Command + B for Mac users. You will get the following output.
You are now all setup to run Python3 code on Sublime Text
Happy Coding 🙂
I want to configure Sublime Text 3 to build Python 3, but I don’t seem to understand how the builds work. Many tutorials have told me to make a build file containing code such as:
and save it as a file called Python.sublime-build
or python3.sublime-build
(much of the information I found was conflicting). One tutorial suggested creating a new folder in the ST3 Packages folder called Python
and add the build file in there, whilst other tutorials suggested leaving it in the folder called User
.
One tutorial explained how I had to change the Environment Variable path
on my operating system to get it to work. That didn’t seem to help either.
I added a folder Python
to Packages
(since it wasn’t there already) and added in a build file with the name Python.sublime_build
which featured only the code I posted above in it. Now when I attempt to run Sublime Text it gives me this error:
The reason you’re getting the error is that you have a Unix-style path to the python
executable, when you’re running Windows. Change /usr/bin/python3
to C:/Python32/python.exe
(make sure you use the forward slashes /
and not Windows-style back slashes ). Once you make this change, you should be all set.
Also, you need to change the single quotes '
to double quotes '
like so:
The .sublime-build
file needs to be valid JSON, which requires strings be wrapped in double quotes, not single.
If you are using PyQt, then for normal work, you should add “shell”:”true” value, this looks like:
Steps to Make Sublime Text a Python IDE (Windows)
Tested successfully on Sublime Text 3. Assuming Sublime Text and package control are already installed . . .
Install Python (python.org) and pay attention to where it is installed or choose a simple location like the C drive, agreeing to remove character limit at the end of the installation.
Install package SublimeREPL (Cntrl + Shift + P, Package Control – Install Package, SublimeREPL, Enter).
Go to Preferences, Package Settings, SublimeREPL, Settings – User.
Paste in the following, updating the file path to your python installation folder, as needed. You may customize these and choose whatever syntax you like (last line) but I prefer my output in plain text.
Save and close the file (SublimeREPL.sublime-settings).
Go to Tools, Build System, New Build System.
Replace all existing text with the following:
Cntrl + S or save as “C:Users[username]AppDataRoamingSublime Text 3PackagesUserSublimeREPL-python.sublime-build” updating username or path as needed. This should be wherever your settings and builds are stored by Sublime Text.
Go to Tools, Build System, select SublimeREPL-python.
All done–now to test. Open or create a simple python file, having a *.py extension and save it wherever desired.
Make sure the file is open and selected in Sublime Text. Now, when you press Cntrl + B to build and run it, it will open another tab, titled “REPL [python]”, executing and displaying the results of your python code.
If you would like to go a step further, I highly recommend making the follow changes, to allow Sublime to reload your executed python in the same window, when you press Cntrl+B (Build), instead of it opening a new tab each time:
Add the following line in the “repl_python_run” command in (Preferences, Browse Packages) SublimeREPLconfigPythonMain.sublime-menu, right before the “external_id”: “python” argument:
Use Sublime Text With Python
and then to change the line:
into:
Sublime Text Run Python 3
in SublimeREPLsublimerepl.py.
Tags: python, text