Sublime Python Ide

broken image


Bohemian code sketch. A solid text editor is a developer's best friend. You use it constantly and itbecomes like a second pair of hands. The keyboard commands you use dailybecome so engrained in your muscle memory that you stop thinking about thementirely.

  • 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.
  • Anaconda Python IDE. Anaconda turns your Sublime Text 3 into a full featured Python development IDE. Download Anaconda v2.1.17 Use Package Control.

Sublime text doesn't support that. But you can get around it (at least in python) by using SublimeREPL, I use this for everything, it works pretty great. Its a little cooky though, as the tab is still editable like a normal sublime tab (which is good and bad). It also allows you to run the interpreter in multiple tabs, its basically awesome.

With Sublime Text, it's possible to turn your text editor into the functionalequivalent of a Python IDE. The best part is you don't have to install an IDEto do it.

Requirements¶

Here are my requirements for an ‘IDE':

  • It should provide excellent, configurable syntax colorization.
  • It should allow for robust tab completion.
  • It should offer the ability to jump to the definition of symbols in otherfiles.
  • It should perform automatic code linting to help avoid silly mistakes.
  • It should be able to interact with a Python interpreter such that whendebugging, the editor will follow along with the debugger.

Which Version?¶

Version 2 will be fine, but I would urge you to consider updating to version 3.Some of the plugins I recommend are not available for version 2.

Basic Settings¶

All configuration in Sublime Text is done via JSON. It's simple to learn. goand read that link then return here.

There are a number of different levels of configuration in Sublime Text. Youwill most often work on settings at the user level.

Open Preferences -> Settings-Default to see all the default settingsand choose which to override.

Create your own set of preferences by opening Preferences -> Settings-User. This will create an empty file, you can then copy the settings you wantto override from the default set into your personal settings.

Here's a reasonable set of preliminary settings (theme, color scheme and fontare quite personal, find ones that suit you.):

Especially important is the setting translate_tabs_to_spaces, which ensuresthat any time you hit a tab key, the single t character is replaced by fours characters. In Python this is vital!

Note

Remember, the font, color scheme and theme settings above are those Iuse. You will need to install extra packages to get them.

Extending the Editor¶

Most of the requirements above go beyond basic editor function. Use Plugins.

Sublime text python ide

Sublime Text comes with a great system for Package Control. It handlesinstalling and uninstalling plugins, and even updates installed plugins foryou. You can also manually install plugins that haven't made it to the big-timeyet, including ones you write yourself. Happily, the plugin system isPython!

Installing Package Control¶

Note

Some earlier versions of Sublime Text came with the package control systemalready installed. This is no longer the case. You'll need to install ityourself. Follow the instructions athttps://sublime.wbond.net/installation.

To install a plugin using Package Control, open the commandpalette withshift-super-P (ctrl-shift-P on Windows/Linux). The super key is commandor on OS X. When the palette opens, typing install will bring up thePackageControl:InstallPackage command. Hit enter to select it.

After you select the command, Sublime Text fetches an updated list of packagesfrom the network. It might take a second or two for the list to appear. When itdoes, start to type the name of the package you want. Sublime Text filters thelist and shows you what you want to see. To install a plugin, select it withthe mouse, or use arrow keys to navigate the list and hit enter when yourplugin is highlighted.

Useful Plugins¶

Here are the plugins I've installed to achieve the requirements above.

Autocompletion¶

By default, Sublime Text will index symbols in open files and projects, butthat doesn't cover installed python packages that may be part of a non-standardrun environment. Undertale megalovania gameplay.

There are two to choose from:

  1. SublimeCodeIntel offers strong support for multiple languages throughit's own plugin system. It is a bit heavy and requires building an index.
  2. SublimeJedi only supports Python, but is faster and keeps an index on itsown.

I've installed SublimeJedi, and used settings similar to thesefor each projectto ensure that all relevant code is found:

The python_interpreter_path allows me to indicate which Python executableshould be introspected for symbol definitions.

The python_package_paths setting allows designating additional paths thatwill be searched for Python packages containing symbols. In the above case, Iam using buildout to manage installed packages, andthe omeletterecipe to provide a single folder in which all installed code can bereferenced. If you work with virtualenvor some other sandbox system, your value for python_package_paths will lookquite different.

Once configured, you should be able to use the ctrl-shift-G keyboardshortcut to jump directly to the definition of a symbol. You can also usealt-shift-F to find other usages of the same symbol elsewhere in your code.

Code Linting¶

Code linting shows you mistakes you've made in your source before you attemptto run the code. This saves time. Sublime Text has an available plugin for codelinters called SublimeLinter.

Python has a couple of great tools available for linting, the pep8 andpyflakes packages. Pep8 checks for style violations, lines too long,extra spaces and so on. Pyflakes checks for syntactic violations, likeusing a symbol that isn't defined or importing a symbol you don't use.

Sublime

Sublime Text comes with a great system for Package Control. It handlesinstalling and uninstalling plugins, and even updates installed plugins foryou. You can also manually install plugins that haven't made it to the big-timeyet, including ones you write yourself. Happily, the plugin system isPython!

Installing Package Control¶

Note

Some earlier versions of Sublime Text came with the package control systemalready installed. This is no longer the case. You'll need to install ityourself. Follow the instructions athttps://sublime.wbond.net/installation.

To install a plugin using Package Control, open the commandpalette withshift-super-P (ctrl-shift-P on Windows/Linux). The super key is commandor on OS X. When the palette opens, typing install will bring up thePackageControl:InstallPackage command. Hit enter to select it.

After you select the command, Sublime Text fetches an updated list of packagesfrom the network. It might take a second or two for the list to appear. When itdoes, start to type the name of the package you want. Sublime Text filters thelist and shows you what you want to see. To install a plugin, select it withthe mouse, or use arrow keys to navigate the list and hit enter when yourplugin is highlighted.

Useful Plugins¶

Here are the plugins I've installed to achieve the requirements above.

Autocompletion¶

By default, Sublime Text will index symbols in open files and projects, butthat doesn't cover installed python packages that may be part of a non-standardrun environment. Undertale megalovania gameplay.

There are two to choose from:

  1. SublimeCodeIntel offers strong support for multiple languages throughit's own plugin system. It is a bit heavy and requires building an index.
  2. SublimeJedi only supports Python, but is faster and keeps an index on itsown.

I've installed SublimeJedi, and used settings similar to thesefor each projectto ensure that all relevant code is found:

The python_interpreter_path allows me to indicate which Python executableshould be introspected for symbol definitions.

The python_package_paths setting allows designating additional paths thatwill be searched for Python packages containing symbols. In the above case, Iam using buildout to manage installed packages, andthe omeletterecipe to provide a single folder in which all installed code can bereferenced. If you work with virtualenvor some other sandbox system, your value for python_package_paths will lookquite different.

Once configured, you should be able to use the ctrl-shift-G keyboardshortcut to jump directly to the definition of a symbol. You can also usealt-shift-F to find other usages of the same symbol elsewhere in your code.

Code Linting¶

Code linting shows you mistakes you've made in your source before you attemptto run the code. This saves time. Sublime Text has an available plugin for codelinters called SublimeLinter.

Python has a couple of great tools available for linting, the pep8 andpyflakes packages. Pep8 checks for style violations, lines too long,extra spaces and so on. Pyflakes checks for syntactic violations, likeusing a symbol that isn't defined or importing a symbol you don't use.

Another Python linting package, flake8 combines these two, and adds inmccabe, a tool to check the cyclomatic complexity of code you write. Thiscan be of great help in discovering methods and functions that could besimplified and thus made easier to understand and more testable.

There is a nice plugin for the SublimeLinter that utilizes flake8. For it towork, the plugin will need to have a Python executable that has the Pythontools it needs installed.

Use `virtualenv`_ to accomplish this. First, create a virtualenv and activateit:

Then use Python packaging tools to install the required packages:

The Python executable for this virtualenv now has the required packagesinstalled. You can look in /path/to/sublenv/bin to see the executablecommands for each:

(sublenv)$ ls sublenv/binactivate easy_install-2.7 pip2.7activate.csh flake8 pyflakesactivate.fish pep8 pythonactivate_this.py pip python2easy_install pip2 python2.7

Now install SublimeLinter and then SublimeLinter-flake8 using Package Control.

Here are the settings you can add to Preferences -> PackageSettings ->SublimeLinter -> Settings-User:

The paths key points to the path that contains the flake8 executablecommand.

The python_paths key points to the location of the python executable to beused.

The settings inside the flake8 object control the performance of thelinter. Read more about them here.

White Space Management¶

One of the issues highlighted by flake8 is trailing spaces. Sublime textprovides a setting that allows you to remove them every time you save a file:

Do not use this setting

Removing trailing whitespace by default causes a ton of noise in commits.

Keep commits for stylistic cleanup separate from those that make importantchanges to code.

The TrailingSpaces SublimeText plugin can help with this.

Here are the settings you can use:

This allows trimming whitespace on save, but only on lines you have directlymodified. You can still trim all whitespace manually and keep changesetsfree of noise.

Follow-Along¶

The final requirement for a reasonable IDE experience is to be able to follow adebugging session in the file where the code exists.

There is no plugin for SublimeText that supports this. But there is a Pythonpackage you can install into the virtualenv for each of your projects that doesit.

The package is called PDBSublimeTextSupport and its simple to install with pip:

With that package installed in the Python that is used for your project, anybreakpoint you set will automatically pop to the surface in SublimeText. Andas you step through the code, you will see the current line in your SublimeText file move along with you.

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 Text 3 Editor – Start Programming With Sublime

Introduction

Text Editor Download

  • 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.

Also Read : Run Python On Android – How To Run Python Programs On Android

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 –

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.

Setting Up Sublime For Python

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

2
4
6
8
num1=7
# Add two numbers
print('The sum of {0} and {1} is {2}'.format(num1,num2,sum))

Running The Code

  • 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.

Also Read : NodeJS vs Python : Which One Is Better

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.
  • 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.
  • Now go to Preference->Package Control. Inside this you will see, there is tons of packages for sublime. Now click on Install Packages.
  • On click Install Package a popup will appear as below.
  • Now inside this textbox type SublimeREPL as below and select the first option and click enter. This will install the plugin.
  • You will see installing package on the bottom while installing.
  • 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.

  • 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 !!!!

Also Read : What Can You Do With Python : Some Cool Things You Can Do With Python

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





broken image