Return to site

Sublime Text Python

broken image


In this tutorial you will learn how to run python program in sublime text in windows.

  1. Sublime Text Editor For Python
  2. Using Sublime Text For Python
  3. Sublime Text Python Linter
  4. Sublime Text Python 3

Just follow below steps to configure sublime text. The whole process is divided into two parts.

Part 1: Setting Path

Sublime Text Editor For Python

Iina 1 0 3 fraction. SublimeText3 package to format python code using black formatter. Black: Diff to see the changes that would be done to the file.; Black: Format to format the file in place using black. Open the folder in Sublime Text. I've set my mac up to use Sublime Text from the command line. Set up the Sublime Text project. When you create a new Sublime Text project, you can specify how it handles builds and tests. This allows me to specify the exact version of python without having to go to the command line.

First of all you have to set the path of python installation directory in environment variable. You can skip this step if it is already done.

1. Copy the path of python installation directory. In my case it looks like as shown below.

C:UsersTCPAppDataLocalProgramsPythonPython36-32

Note: Here TCP is the user name of my computer. It will be different in your case.

2. Now right click on Computer and click on Properties option. Then select Advance system settings in left sidebar.

3. Now click on Environment Variables and then under System variables select variable with name Path.

4. Click Edit button and then in Variable value field go to end and type semicolon and then paste the path of python directory that you copied. See below screenshot.

5. Finally click on all OK buttons to save the settings.

Part 2: Install SublimeREPL Plugin

For taking input from user in sublime text we need a plugin named as SublimeREPL. So follow below steps to install it.

1. Go to below link and copy the code according to your sublime text version.

2. Open sublime and go to View > Show Console. Then in console box at bottom paste the code that you have just copied and press enter. Wait for few seconds, it will install required packages.

3. Then go to Preferences > Package Control > Package Control: Install Package.

4. In textbox type SublimeREPL and select it to install the plugin. After installation restart sublime text.

5. Now got to Tools > Build System > New Build System. A new file will open, just paste the following code in it.

2
4
'target':'run_existing_window_command',
'file':'config/Python/Main.sublime-menu'

6. Press ctrl + s and save it with file name Python_RUN.

7. Go to Tools > Build System and select Python_RUN as build system or you can use ctrl + b as shortcut.

Using Sublime Text For Python

8. For running a python program go to Tools > Build.

Sublime Text Python Linter

Video Tutorial

Comment below if you are facing any problem to run python program in sublime text.

You May Also Like:

Written by a Google engineer sublime text is a cross-platform IDE developed in C++ and Python. It has basic built-in support for Python. Sublime text is fast and you can customize this editor as per your need to create a full-fledged Python development environment. You can install packages such as debugging, auto-completion, code linting, etc. There are also various packages for scientific development, Django, Flask, and so on.

Downloading and Installation

Sublime Text 3 can be downloaded from its official site sublimetext.com. To install sublime text 3 on Windows, go through How to install Sublime Text 3 in Windows?

Setting up Environment Variable

  • Step 1: Click the Advanced system settings link.
  • Step 2: Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • Step 3: In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Sublime Text Python

Working on Sublime Text3

Step 1: Create a new file and save it with extension .py for example save it as checkversion.py. Now, Go to Tools -> Build System -> Python then type on your checkversion.py
This is showing the version of python. This means python is successfully installed and added in Environment Variable.

Step 2: Add new build system on your Sublime Tools -> Build System -> New Build System and make sure that the new build system has this following command

'cmd':['C:/Users//AppData/Local/Programs/Python/Python37-32/python.exe', '-u', '$file'],
'file_regex': '^[ ]File '(..?)', line ([0-9]*)',
}

Select your new system build newPython3 and re-run the checkversion.py and now it should be using Python 3

Sublime Text Python 3

ALL Done…
Now create any file and save it with .py extension

Now you can run your Python code by using CTRL+SHIFT+B and choose from the 2 options.

Recommended Posts:

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the 'Improve Article' button below.






broken image