Sublime run python file

How to Run Python Program in Sublime Text

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

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

Part 1: Setting Path

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:\Users\TCP\AppData\Local\Programs\Python\Python36-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.

How to Run Python Program in Sublime Text 1

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.

How to Run Python Program in Sublime Text 2

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.

How to Run Python Program in Sublime Text 3

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

How to Run Python Program in Sublime Text 4

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

How to Run Python Program in Sublime Text 5

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

Источник

Sublime Run Python – Running Python Programs On Sublime Text 3

Hi Python Developers, welcome to new post Sublime Run Python tutorial. Here we will learn how to run python programs on Sublime Text 3 editor, downloading and installing Sublime Text 3, installing packages and many more. So let’s move ahead.

There are various IDEs and Text editors are present to run python code. If you are a beginner then it’s ok to use text editor but if you are a developer then no doubt you will be familiar with the importance of IDEs. And you can also refer this link Best Python IDEs for a detailed explanation of Python IDEs . Although Sublime Text 3 is a text editor but it has some IDE-like functions, such as projects and “builds” to execute other programs from inside the editor.

So now we will see some worthful informations about Sublime Text 3 editor.

Sublime Run Python

Sublime Text 3 Editor – Start Programming With Sublime

Introduction

  • It is a light weight editor for developers.
  • It is most popular among developers.
  • The best thing of Sublime Text 3 is that it does not require much of installation space and working with it is very handy and comfortable.
  • Sublime Text 3.0 was released on 13 September 2017.
  • Jon Skinner and Will Bond are the developers of Sublime Text 3.
  • It natively supports lots of programming languages as well as markup languages.

Features Of Sublime Text 3

Cross Platform

  • Sublime Text 3 can run on Windows, Linux and Mac.
  • You have to need only one licence to use Sublime Text 3 on every computers on which you want to use Sublime Text 3, it doesn’t matter which OS they are using.

Powerful API and Package Ecosystem

  • Sublime Text 3 provides many powerful Python API that allows plugin to perform many built-in functionality.
  • Sublime Text exposes its internals via an Application Programming Interface (API) that programmers can interact with using the Python programming language.
  • An embedded Python interpreter is included in the editor. The embedded interpreter is useful to inspect the editor’s settings and to quickly test API calls while developing plugins.

Goto Anything

  • It is the most powerful feature of Sublime Text 3.
  • This feature allows you to open files only with a few keystrokes.
  • It also allows you to instantly jump to symbols, lines or words.
  • For using this feature you have to press Ctrl+P button, then type – If you want to open a file then just type the part of file name, if you want to jump to symbols then type @, if you want to search anything within a file then simply type #, and now if you want to go to into a specific line number : .
  • For eg. if you type tp:100 that would take you to line 100 of the file.

Command Palette

  • This is an another powerful feature of Sublime Text 3.
  • It allows you to do various functionalities like sorting, syntax changing as well as changing identition settings.
  • Using command palette you can access a lots of things like handling sublime projects, changing file syntax, calling your package commands etc.
  • To use command palette – press ctrl+shift+p, then select command and press Enter.

Multiple Selections

  • It is one of the best feature of Sublime Text 3.
  • By using this feature you will be able to change multiple lines simultaneously and also can manipulate files faster.
  • It works as a quick substitute for find and replace, or to apply the same sequence of changes to multiple lines simultaneously.
  • To use Multiple Selection, select a block of text, then press Ctrl+Shift+L to split it into one selection per line and then press Ctrl+D to select the next occurrence of the selected word.

GoTo Definition

  • Sublime Text 3 introduced the most awaiting feature i.e. the “Goto Definition” functionality.
  • GoTo Definition uses the symbol index created by sublime text.
  • To use Go To Definition press alt+g .

Snippets

  • Snippets allows users to save blocks of frequently used code and assign keywords to them.
  • The user can then type the keyword and press tab to paste the block of code whenever they require it.

Others Features

Apart from the above features Sublime Text 3 has also some other features like –

  • Spell check function
  • Auto save
  • Customizable key bindings
  • Macros
  • Split editing
  • Customize anything

So now we will discuss running python programs on Sublime Text 3.

Sublime Run Python Tutorial – Run Your First Program

No doubt Sublime text is the most loved text editor in the developer’s community and can serve as a great Python text editor. So now we will see how to use it for python.

Downloading And Installing

First of all you have to download it. The link for downloading is Sublime Text 3.

You will see a version description as follows –

Sublime Run Python

And now you have to select one as your machine requirement. My machine is Windows-64 bit so i am downloading Windows-64 bit version.

And now install the downloaded file.

Setting Path

Once you have installed it then you have to set the path of python installation directory in environment variable. If your path is already set then you can skip this part otherwise follow this link Setting Path . As i have already set the path so i am skipping it.

Test A simple Program

Now we will see execution of python program on Sublime Text 3. For this what we have to do is that –

  • First of all open your sublime editor.
  • Create a new file by following steps File->New File or by pressing ctrl+N .
  • Then save this file as yourfilename.py . The extension must be .py .
  • Then write your code.

Here i am taking a simple program i.e., addition of two numbers. So code is –

Running The Code

Sublime Run Python

  • Go to Tool option on menu bar and then click on Build System and inside this select Python option.
  • Then go to Tool option and click on Build option that will execute your code. So now, on running the above code we will get the following output.

Hey guys congratulations, our python code is running successfully on sublime. And now it’s time to move ahead.

Taking Input From User

Now we will see how to take input from user on sublime text 3.

Taking input is super easy in python, but working on sublime text 3 we have to do some settings. So let’s see what they are –

Install SublimeREPL Plugin

  • SublimeREPL is a plugin for Sublime Text that lets you run interactive interpreters of several languages within a normal editor tab. It also allows connecting to a running remote interpreter (e.g. Clojure/Lein) though a telnet port.
  • SublimeREPL has a built-in support for command history and transferring code from open buffers to the interpreters for evaluation, enabling interactive programming.

Where the sample program runs on sublime is not meant for as a comment prompt, this is meant for output. To do this we actually use PackageManager.

  • Visit Package Control and copy the code according to your sublime version.

Sublime Run Python

  • Then back over to sublime text and go to View->Show Console. And now you have to paste the copied code here and hit enter. After a few second your package will be install.

Sublime Run Python

  • Now go to Preference->Package Control. Inside this you will see, there is tons of packages for sublime. Now click on Install Packages.Sublime Run Python
  • On click Install Package a popup will appear as below.

Sublime Run Python

  • Now inside this textbox type SublimeREPL as below and select the first option and click enter. This will install the plugin.

Sublime Run Python

  • You will see installing package on the bottom while installing.

Sublime Run Python

  • Now go to Tools->SublimeREPL->Python->Python-RUN current file. That will execute our current file. So let’s see what’s the output.

That’s pretty cool running python programs on Sublime Text 3. So going to Tools->SublimeREPL->Python->Python-RUN current file each time is a major pain so now we can create a shortcut for this.

Sublime Run Python

  • Go to Preferences->Key Bindings , a new window will appear now you have to write the following code. This code is created by me you can create this shortcut as you want.

So now you have not go to along with a lengthy running process, you just have to press ctrl+alt+b. That’s super cool .

So friends, this was all about the Sublime Run Python tutorial. I hope this tutorial will be helpful for you. And if you have any query regarding this then leave your comment. And please share this as much as possible. Thanks everyone

Источник

Как в Sublime Text 3 запускать код Python-a?

Пишу код Python в Sublime Text 3, но чтобы проверить как программа работает, надо запускать программу через консоль.
Подскажите, как запускать python код через этот редактор.
Заранее спасибо!

Средний 4 комментария

Возможно, не совсем по теме, но как Python-программист, советую, попробуйте PyCharm. Вы забудете про Саблайм очень быстро 😉

sintez: Не не не. ST сложно выпилить «из пальцев» 😉 Он как «вторая кожа» 😉 Проще VIM-ера уговорить пересесть на Visual Studio, чем юзера ST на PyChar )

yarkov

Есть много вариантов, первый это ctrl + b, но он не поддерживает ввод. Поетому советую использовать SublimeRELP, установить его не так сложно, просто воспользуйтесь Package Control -> Install Package -> SublimeRELP. Теперь ви можете Tools -> SublimeRELP -> Python -> Run Current file. Но это поддерживает только Python2.7 и пользоваться не удобно. Для того что бы исправить это все открываем Preferences -> Key Bindings -> User и добавляем такое:

(в квадратние скобки).
Теперь при Ctrl + b все должно работать.

выдаёт ошибку WindowsError(2, ‘\xcd\xe5 \xf3\xe4\xe0\xe5\xf2\xf1\xff \xed\xe0\xe9\xf2\xe8 \xf3\xea\xe0\xe7\xe0\xed\xed\xfb\xe9 \xf4\xe0\xe9\xeb.’)

Если у кого не работает. не забывайте обернуть в квадратные скобки
У меня всё заработало, когда я внес минимальные правки в строку:

«cmd»: [«python3», «-u», «$file_basename»],
«cwd»: «$file_path»,
изенил на:

«cmd»: [«python», «-i», «-u», «$file_basename»],
«cwd»: «$file_path»,

FIONover

Спасибо, дай бог здоровья тебе! Не забывайте запятую поставить перед всей конструкцией, если у вас был код до этого, и главное общий код чтобы был в [ ]

Источник

Читайте также:  Read object method in java
Оцените статью