Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Python Development in Sublime Text

Tech 1

To establish a functional Python development environment in Sublime Text, begin by defining a custom build system. Navigate to Tools > Build System > New Build System... to generate a default JSON configuration file. Replace the template with the following structure, ensuring the executable path points to your specific Python interpreter location:

{
  "encoding": "utf-8",
  "shell_cmd": "python -u \"$file\"",
  "working_dir": "$file_path",
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  "selector": "source.python",
  "env": {"PYTHONIOENCODING": "utf-8"}
}

Save this configuration as Python3.sublime-build in the default directory. Activate it via Tools > Build System by selecting your newly created profile. Verify functionaltiy by executing a script with Ctrl+B.

Editor Customization Modify the user preferences to adjust typography and color schemes. Access Preferences > Settings and append the following parameters to the right-hand configuration pane:

{
  "font_face": "Fira Code",
  "font_size": 13,
  "theme": "Adaptive.sublime-theme",
  "color_scheme": "Mariana.sublime-color-scheme",
  "tab_size": 4,
  "translate_tabs_to_spaces": true
}

Package Manager Initialization The ecosystem relies on Package Control for extension management. Open the console via Ctrl+`` or View > Show Console. Execute the initialization script to fetch the core module. Modern installations utilize urllib` for network requests:

import urllib.request, ssl, os
from pathlib import Path

target_module = 'Package Control'
package_file = f'{target_module}.sublime-package'
install_location = Path(sublime.installed_packages_path())
destination = install_location / package_file

download_url = f'https://packagecontrol.io/{package_file.replace(" ", "%20")}'
ssl_context = ssl._create_unverified_context()

with urllib.request.urlopen(download_url, context=ssl_context) as network_response:
    with open(destination, 'wb') as output_stream:
        output_stream.write(network_response.read())

print('Installation complete. Restart the editor to load extensions.')

Alternatively, download the .sublime-package file manually and place it directly into the Installed Packages directory accessible via Preferences > Browse Packages. After restarting, the command palette (Ctrl+Shift+P) will recognize Install Package and List Packages.

Core Plugin Configuration SublimeCodeIntel: Provides intelligent code completion and definition jumping. After installation, create a .codeintel directory inside the plugin’s package folder. Within it, generate a config file to map the interpreter and library paths:

language_settings = {
    "Python3": {
        "executable_path": "C:\\Python311\\python.exe",
        "search_directories": [
            "C:\\Python311",
            "C:\\Python311\\Lib",
            "C:\\Python311\\DLLs",
            "C:\\Python311\\Lib\\site-packages"
        ]
    }
}

SublimeREPL: Enables interactive console execution directly within the editor. Configure custom keybindings in Preferences > Keybindings to trigger REPL sessions:

[
  {
    "keys": ["ctrl+shift+r"],
    "command": "run_existing_window_command",
    "args": {
      "id": "repl_python_interactive",
      "file": "config/Python/Main.sublime-menu"
    },
    "caption": "Interactive Python Console"
  },
  {
    "keys": ["f8"],
    "command": "repl_open",
    "args": {
      "type": "subprocess",
      "cmd": ["python3", "-i", "$file_basename"],
      "cwd": "$file_path",
      "encoding": "utf8",
      "external_id": "python3_repl",
      "extend_env": {"PYTHONIOENCODING": "utf-8"}
    }
  }
]

SublimeTmpl: Streamlines file creation using predefined templates. Adjust the user settings to define metadata placeholders:

{
  "template_metadata": {
    "author": "Developer",
    "version": "1.0.0",
    "generated_at": "%Y-%m-%d %H:%M:%S"
  },
  "enable_shortcuts": true
}

Map a shortcut like Ctrl+Alt+N to the sublime_tmpl command targeting the python type. Modify the python.tmpl file in the plugin directory to match your preferred header structure.

Anaconda: Delivers linting, auto-formatting, and advanced completion. Point the interpreter in the user settings and disable conflicting built-in features:

{
  "python_interpreter": "C:\\Python311\\python.exe",
  "suppress_word_completions": true,
  "auto_formatting": true,
  "pep8_ignore": ["E501", "W391"],
  "anaconda_linting_behaviour": "save-only"
}

Emmet: Accelerates HTML and CSS authoring. If dependencies fail to resolve automatically, manually acquire the PyV8 binary from the official repository. Extract the archive in to the Packages directory and rename the folder to PyV8 before restarting.

Resolving Package Repository Errors Network restrictions occasionally prevent Package Control from fetching channel_v3.json. Bypass this by downloading the repository list manually and referencing it locally:

{
  "repositories": [
    "https://packagecontrol.io/channel_v3.json"
  ],
  "channels": [
    "D:\\Config\\Sublime\\channel_v3.json"
  ]
}

Apply this configuration in the Package Control user settings to force local resolution. Verify that extensions now appear in the installation menu.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.