Run Python Code in Sublime Text 3
Sublime Text is a popular code editor. It supports many markup and programming languages, within which we can add functions via plugins, which are community-built and maintained under free software licenses. You can find the steps to install sublime on Ubuntu here if sublime is not installed yet.
This tutorial will discuss how to run Python code in sublime text 3.
We can run Python code inside the Sublime Text with the use of these built-in build systems. By pressing Ctrl + B , Sublime 3 will run the python code inside the integrated console (provided we have saved the file with .py file extension).
But a problem with this implementation is that with this method, we cannot perform interactive activities like performing user input functions using input() or any other interaction with the program.
For this, we press Ctrl + Shift + P in Windows and type Install Package Control . macOS users can use the Cmd + Shift + P for the same.
Then we need to install Terminus via Package Control. So we again press the same keys and type Package Control: Install Package and then type Terminus .
We then go to the Tools menu and select the Build System option. Here we choose New Build System and paste the code below.
For windows, change the path to Python.
"target": "terminus_exec", "cancel": "terminus_cancel_build", "shell_cmd": "D:\\.python_venvs\\general_python\\Scripts\\python.exe -u \"$file\"", "file_regex": "^[ ]*File \"(. *?)\", line ([0-9]*)", "selector": "source.python", "env": "PYTHONIOENCODING": "utf-8">, "variants": [ "name": "Syntax Check", "shell_cmd": "D:\\.python_venvs\\general_python\\Scripts\\python.exe -m py_compile \"$\"", > ] >
For Mac/Linux, change the path to Python.
"target": "terminus_exec", "cancel": "terminus_cancel_build", "shell_cmd": "/home//.python_venvs/general_python/Scripts/python -u \"$file\"", "file_regex": "^[ ]*File \"(. *?)\", line ([0-9]*)", "selector": "source.python", "env": "PYTHONIOENCODING": "utf-8">, "variants": [ "name": "Syntax Check", "shell_cmd": "/home//.python_venvs/general_python/Scripts/python -m py_compile \"$\"", > ] >
We can name the file and select this Custom Build System to run the code.
Related Article — Python Run
- Run Python in Notepad++
- Run Python in Atom
Copyright © 2023. All right reserved
Как запускать код Python 3 в sublime text 3?
Помогите пожалуйста! весь интернет излазил. Но не нашёл. Пожалуйста расскажите как. Можно пожалуйста пошагово. (я сохранял).
Голосование за лучший ответ
а в чём собственно проблема вы скачали питон и саблайн? Если да то просто пишем код в саблайне и сохраняем при чтении выбираем открыть через саблайн
Кирилл ВоробьевУченик (124) 2 года назад
ТЫ ТУПОЙ. ТЕБЕ ЧЕЛОВЕК ПИШЕТ ПРО КОД. » КОД. » И ПРО ТО КАК ЕГО ЗАПУСКАТЬ. » ЗАПУСКАТЬ. »
ну так это редактор а не ide
в сублиме сохранил, потом запускаешь фаил через cmd (предварительно забив переменную окружения). По крайней мере именно так рекомендуют делать в книгах у саммерфилда и в byte of python
Есть много вариантов, первый это ctrl + b, но он не поддерживает ввод. Поэтому советую использовать SublimeRELP, установить его не так сложно, просто воспользуйтесь Package Control -> Install Package -> SublimeRELP. Теперь вы можете Tools -> SublimeRELP -> Python -> Run Current file.
Дмитрий Акинин
Запуск Python 3 в консоли Sublime Text 3 (Mac OS X)
Идем в меню Tools > Build System > New Build System… В появившийся документ вставляем:
< "path": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", "env": < "PYTHONPATH":"/usr/local/lib/python:/usr/local/username/python/3.3/lib/python3.3/" >, "cmd": ["python3", "-u", "$file"], "file_regex": "^[ ]*File \"(. *?)\", line ([0-9]*)", "selector": "source.python", "encoding": "utf-8", "env": >
Сохраняем под названием Python 3. Ура, теперь можно запускать скрипты на 3-м python прямо из консоли Sublime через Cmd+B.
Как запускать код python в sublime text 3
По умолчанию в Sublime Text 3 python-скрипты выполняются с помощью команды python. При этом в Ubuntu 14.04 эта команда соответствует python версий 2.х. Чтобы выполнять скрипты в python версии 3.х (с помощью команды python3) необходимо выполнить следующие действия:
Выбираем в меню: Tools -> Build System -> New Build System
Вводим в открывшемся окне:
где absolute_path_to_python_binary — абсолютный путь до бинарников python3, который можно получить с помощью команды:
which python3
Затем сохраняем, и в меню Tools -> Build System выбираем схему по имени, под которым мы ее ранее сохранили.
