Sublime Python Interpreter



  1. 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.
  2. Configure Anaconda the Right Way. Anaconda works fine out of the box (always that there is a Python interpreter configured in your path and the binary is named python) but if you want to get the max from it, you can configure multitude of options to tune it and adapt it to your needs. To take a look at the common configuration of the Anaconda powerful IDE features, take a look at the Powerful.

In this Python Tutorial, we will be setting up a development environment in Sublime Text 3. We will walk through how to install Sublime Text, install Package.

- 2 mins

Packages and Setup

Type Checker: mypy

1. Install mypy

Alternatively, you can

2. Test mypy

Error pops up:

Solution:

3. Install Anaconda

Package Control -> Install Package -> Anaconda

4. Configure Anaconda

Preferences -> Package Settings -> Anaconda -> Settings-User

5. SublimeLinter-contrib-mypy

Instruction:
(1) Package Control -> Install Package -> SublimeLinter
(2) Package Control -> Install Package -> SublimeLinter-contrib-mypy

6. mypy configuration file

When importing third party module, import numpy for instance, it would pop up an error:

That’s because Numpy does not have stable type hints at this time.

Three ways to fix it:

  • Append # type: ignore after the module name:
  • On the command line:

This has the drawback that it will ignore mistakes as well (misspelling the package name, for example)

  • We can create a .mypy.iniconfiguration file in our home folder ~ (or a mypy.ini in the folder where our project is) with the following content:

Run Python

Run Python3 on Sublime Text 3:
Tools -> Build System -> New Build System:

UNIX

WINDOWS

Save this file as new-python.sublime-build

Go to Tools -> Build System -> Python
Press CTRL + B to run the code on Sublime

Terminal

Reference

Related Posts

Please enable JavaScript to view the comments powered by Disqus.comments powered by Disqus

Introduction

Sublime is a friendly text editor known for its slick user interface,numerous features, and snappy performance that provides a combinationof many amazing features from modern text editors (and more)!

Sublime is easy to use, and extremely fun to master (I mean, whodoesn't want to use multiple cursors in vim mode while -- you get thepicture, do things with CS words that don't quite make sense rightnow). This guide will get you started with Sublime, with a few basicsand essential tools for your workflow in CS61A. If there's somethingyou want Sublime to do, it's likely possible! A quick Google searchwill probably show you a plugin you can install to extend Sublime'sfunctionality.

Getting Sublime on your own computer

Visit Sublime's website and follow theinstructions to install it on your computer.

Example: greet.py

By now, you should have Sublime installed. You have the optionof either finding the Application or opening it up from the terminal.Recall from Lab 0 that you can open a terminal on the schoolcomputers by pressing Ctrl-Alt-t.

Let's first create and navigate to a directory called example, usingthe UNIX commands you learned in Lab 0:

Opening files

Now let's open up Sublime!

For Mac users, you'll most likely find Sublime in your Applications.

For Ubuntu users, you'll most likely find Sublime by putting it in the searchbar.

For Windows users, you'll most likely find Sublime in yourProgram Files.

Sublime will open up to a blank file. We can start writing our program!

Editing files

Now we have Sublime open, we can begin writing our first Python file.We'll be writing a short program that prints out a greeting whenexecuted. Don't worry, we don't expect you to know any Python yet! Allyou have to do is type in the following:

Once you've finished typing, Sublime should look something like this:

To save, you can just type Ctrl-s. If you haven't already, savethis file as greet.py.

Sublime python download

Spaces and tabs

By default, Python outputs a tab character (t) when you press the tab key.However, for this class we want to indent our code using spaces.Check 'View > Indentation > Indent Using Spaces' to make Sublime output 4 spaceswhenever you press the tab key.

Running Python

Back in our terminal, we're currently in our example directory.Let's play around with our code. In the terminal, start by typing

This command does the following:

  1. python3 is the command that starts Python
  2. The -i flag tells Python to start in interactive mode, which allows you to type in Python commands from your terminal
  3. greet.py is the name of the Python file we want to load

Notice that the Python interpreter says >>>. This means Python isready to take a command.

Recall that we defined a function called greet. Let's see what itdoes! Type in the following:

Python will then print out

Download Python Interpreter

Our code works! Let's close Python by typing in

There are a couple of ways to exit Python. You can type in exit()or quit(). On MacOS and Linux, you can also type in Ctrl-d (thisdoesn't work on Windows).

Congratulations, you've edited your first file in Sublime!

Keyboard Shortcuts

Sublime Python Ide

Sublime has a some swell keyboard shortcuts. Here are a few usefulones! (for Mac users, replace all the Ctrl sequences with cmd)

  • Ctrl-s : saves the current file
  • Ctrl-x : cuts the entire line your cursor is on
  • Ctrl-v : pastes the entire line you cut in the line above your cursor OR pastes the selected text in place
  • Ctrl-z : undo
  • Ctrl-y : redo
  • Ctrl-[ : indent a line or a group of lines
  • Ctrl-] : dedent a line or a group of lines
  • Ctrl-d (my favorite!): highlights the current word. For every 'Ctrl-d' you type after this first word, it will highlight every next instance of the word. This allows you to easily rename variables with multiple cursors! (Play around with this one, it's fun!)
  • Ctrl-tab : moves you to the next tab
  • Ctrl-shift-tab : moves you to the previous tab
  • Ctrl-f : search for a word
  • Ctrl-shift-f : searches through all tabs
  • Ctrl-shift-p : This one's important. This opens up a little panel of tools! You can do things like type 'ss python' which will set the syntax of your file to Python or 'reindent' will help you reindent a file you paste in (this will be helpful in future labs!)

This guide only scratches the surface of Sublime'sfunctionality. Remember, if there's something you wish Sublime coulddo, it probably can! Just Google it!