Table of Contents
Why choose Sublime Text?
Font selection
Install plug-ins
Configuration file" >Configuration file
Key binding
Command Line Tool
Home Backend Development Python Tutorial Detailed graphic and text explanation of the steps to set up Sublime Text's Python development environment

Detailed graphic and text explanation of the steps to set up Sublime Text's Python development environment

Mar 17, 2017 pm 05:16 PM
python sublime development environment

Recently, when I mainly use the Python development environment to edit, I have begun to use Sublinme Text 2 more and more. This article mainly explains how to make Python programmers more convenient to use some settings and adjustments.

图文详解设置Sublime Text的Python开发环境步骤

Why choose Sublime Text?

I have always been a loyal user of TextMate. This is a lightweight, open source software that comes as a native OS X application with a nice Mac feel. However, although TextMate is a great editor, it sometimes lacks functionality.

I have used some more powerful software, such as IntelliJ IDEA with Python plug-in. I particularly like its debugger and test runner. However, a full-featured IDE like IntelliJ is still too large for small and medium-sized projects.

In recent weeks I have started using Sublime Text more and more. Once I installed it, it felt really good. It's really fast, updates automatically and regularly, and best of all, it's fully cross-platform. For me, where it ultimately beats TextMate is Sublime's powerful plugin subsystem. For Python development, there are many plug-ins that can make your development smoother and more fun.

I still switch editors between different projects. However, I found that for Python development, Sublime has a good balance between a lightweight editor and a full-featured IDE.

Font selection

Ubuntu Mono is a very, very good font. I just switched from Menlo a few days ago and I definitely don’t regret it.

On my 15-inch MacBook, Ubuntu Mono’s 16-point font fits perfectly. The resolution of 1680 × 1050 is just right for a sidebar plus two editor windows (which automatically adjust to 80 characters wide).

If you plan to carefully choose a font, this article from slant.co is well written. It contains screenshots and download links for most popular programming fonts.

Install plug-ins

As mentioned before, Sublime has a very rich plug-in system. The plug-ins I currently use are as follows:

  • Package Control The package manager for installing additional plug-ins directly in Sublime. This is the only plugin you have to install manually. All other plugins listed here can be installed via Package Control. You can also use it to update installed plug-ins. It's as simple as apt-get for Sublime packages.

  • Color Scheme - Tomorrow Night Color schemes determine the font color for syntax highlighting in the editor interface. This is a very cool dark style.

  • Theme - Soda Dark Themes affects the color and style of Sublime interface elements. This is a perfect color scheme for Tomorrow Night.

  • SideBarEnhancements This plug-in provides additional context menu options for the sidebar, such as "New file", "New Floder", etc. These should be there by default, but they are not.

  • All Autocomplete Sublime's default autocomplete only focuses on words in the current file. This plugin extends its autocomplete word list to all open files.

  • SublimeCodeIntel enhances the auto-complete function for some languages, including Python. This plugin also allows you to jump to where a symbol is defined by holding down alt and clicking on the symbol. Very convenient.

  • SublimeREPL allows you to run the Python interpreter directly in the editing interface. I prefer running bpython in a separate terminal window, but sometimes SublimeREPL can be helpful.

  • GitGutter In the groove area of ​​the editor, according to Git, add a small icon to identify whether a line is inserted, modified or deleted. The GitGutter readme explains how to change the color icons to update your color scheme file.

  • Pylinter This plug-in provides the best pylint editor integration I have seen so far. It automatically checks .py files whenever they are saved and displays pylint violations directly in the editing interface. It also has a shortcut to disable local pylint checking, by inserting a #pylint: disable comment . This plugin is really useful for me.

Configuration file

One of the advantages of Sublime Text is that all its configurations are simple configurations based on JSON document. This allows you to easily transfer the configuration to another system. I've also seen some people use Dropbox to automatically sync their configuration across all their computers.

 Preferences.sublime-settings configures the display and behavior of Sublimede. You can open and edit this file in sublime through Preferences > Settings — User. I configured the pylinter plug-in using the following configuration:

{
    // Colors
    "color_scheme": "Packages/Tomorrow Color Schemes/Tomorrow-Night.tmTheme",
    "theme": "Soda Dark.sublime-theme",
 
    // Font
    "font_face": "Ubuntu Mono",
    "font_size": 16.0,
    "font_options": ["subpixel_antialias", "no_bold"],
    "line_padding_bottom": 0,
    "line_padding_top": 0,
 
    // Cursor style - no blinking and slightly wider than default
    "caret_style": "solid",
    "wide_caret": true,
 
    // Editor view look-and-feel
    "draw_white_space": "all",
    "fold_buttons": false,
    "highlight_line": true,
    "auto_complete": false,
    "show_minimap": false,
 
    // Editor behavior
    "scroll_past_end": false,
    "highlight_modified_tabs": true,
    "find_selected_text": true,
 
    // Word wrapping - follow PEP 8 recommendations
    "rulers": [ 72, 79 ],
    "word_wrap": true,
    "wrap_width": 80,
 
    // Whitespace - no tabs, trimming, end files with \n
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "ensure_newline_at_eof_on_save": true,
 
    // Sidebar - exclude distracting files and folders
    "file_exclude_patterns":
    [
        ".DS_Store",
        "*.pid",
        "*.pyc"
    ],
    "folder_exclude_patterns":
    [
        ".git",
        "pycache",
        "env",
        "env3"
    ]
}
Copy after login

Pylinter.sublime-settings. I use the following configuration to have Pyhton automatically normalize on save and display icons for violations.

{
    // Configure pylint's behavior
    "pylint_rc": "/Users/daniel/dev/pylintrc",
 
    // Show different icons for errors, warnings, etc.
    "use_icons": true,
 
    // Automatically run Pylinter when saving a Python document
    "run_on_save": true,
 
    // Don't hide pylint messages when moving the cursor
    "message_stay": true
}
Copy after login

Key binding

Sublime’s key bindings are also fully configurable based on the JSON-based sublime-keymap configuration file. I modified some of the default configuration to better suit my TextMate / IntelliJ muscle memory. You don't have to modify it at all. It's easy to modify and can be used cross-platform if you want. I use the following binding:

[
    // Rebind "go to file" to cmd+shift+O
    { "keys": ["super+shift+o"], "command": "show_overlay", "args": {
        "overlay": "goto",
        "show_files": true
    }},
 
    // Rebind swap line up/down to cmd+shift+up/down
    { "keys": ["super+shift+up"], "command": "swap_line_up" },
    { "keys": ["super+shift+down"], "command": "swap_line_down" },
 
    // Delete a line with cmd+delete
    { "keys": ["super+backspace"], "command": "run_macro_file", "args": {
        "file": "Packages/Default/Delete Line.sublime-macro"
    }},
 
    // Reindent selection with cmd+alt+L
    { "keys": ["super+alt+l"], "command": "reindent"}
]
Copy after login

Command Line Tool

Similar to TextMate's mate, Sublime Text includes a command line tool that allows you to open the editor through a shell. The tool is called sublis and is not available by default. To take effect, run the following in any shell:

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

To use Sublime as the default editor for interactive git commands - for example, writing commit messages - just add the following line to your ~/.profile file:

export GIT_EDITOR="subl --wait --new-window"

The above is the detailed content of Detailed graphic and text explanation of the steps to set up Sublime Text's Python development environment. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

How to run sublime code python How to run sublime code python Apr 16, 2025 am 08:48 AM

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

How to automatically type notepad How to automatically type notepad Apr 16, 2025 pm 08:06 PM

Notepad itself does not have automatic layout function. We can use a third-party text editor, such as Sublime Text, to perform the following steps to achieve automatic typography: 1. Install and open the text editor. 2. Open the file that needs to be automatically typed. 3. Find and select the automatic layout function. 4. The editor will automatically type the text. 5. You can customize the layout rules as needed. Automatic typography can save time and ensure text consistency and professionalism.

How to run python with notepad How to run python with notepad Apr 16, 2025 pm 07:33 PM

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

See all articles