Setting Up Sublime Text For Python

1 view
Skip to first unread message

Jasmine Lemaitre

unread,
Aug 3, 2024, 5:51:50 PM8/3/24
to riasnifeves

Split Layouts allow you to arrange your files in various split screens. This is useful when you are doing test driven development (Python code on one screen, test scripts on another) or working on the front end (HTML on one screen, CSS and/or JavaScript on another).

Djaneiro supports Django templating and keyword highlighting and provides useful code snippets (tab completions) for Sublime Text. The snippet system is an incredible time-saver. You can create common Django blocks with only a few keystrokes for templates, models, forms, and views. Check out the official documentation to see a list of snippets.

SublimeLinter is a framework for ST3 linters. The package itself does not include any actual linters; those must be installed separately via Package Control using the SublimeLinter-[linter_name] naming syntax. You can view official linters here. There are also a number of third party linters, which can be viewed in Package Control. Check out the installation instructions here.

You can customize each linter in the user-defined SublimeLinter.sublime-settings file: Sublime Text > Preferences > Package Settings > SublimeLinter > Settings - User. For example, I ignore the following PEP 8 errors and warnings:

Simply bring up the AdvancedNewFile input through the appropriate key binding. Then, enter the path, along with the file name into the input field. Upon pressing Enter, the file will be created. In addition, if the directories specified do not yet exist, they will be created. By default, the path to the file being created will be filled shown in the status bar as you enter the path information.

I replaced the normal Cmd+N command to create a new file with AdvancedNewFile by adding the following code to the Key Bindings - User file: Sublime Text > Preferences > Package Settings > AdvancedNewFile > Key Bindings - User:

I hope that this article was helpful to you and that you were able to integrate some of the above packages and custom settings along with your own based on your personal preferences to improve your workflow.

and save it as a file called Python.sublime-build or python3.sublime-build (much of the information I found was conflicting). One tutorial suggested creating a new folder in the ST3 Packages folder called Python and add the build file in there, whilst other tutorials suggested leaving it in the folder called User.

I added a folder Python to Packages (since it wasn't there already) and added in a build file with the name Python.sublime_build which featured only the code I posted above in it. Now when I attempt to run Sublime Text it gives me this error:

The reason you're getting the error is that you have a Unix-style path to the python executable, when you're running Windows. Change /usr/bin/python3 to C:/Python32/python.exe (make sure you use the forward slashes / and not Windows-style back slashes \). Once you make this change, you should be all set.

Paste in the following, updating the file path to your python installation folder, as needed. You may customize these and choose whatever syntax you like (last line) but I prefer my output in plain text.

Cntrl + S or save as "C:\Users[username]\AppData\Roaming\Sublime Text 3\Packages\User\SublimeREPL-python.sublime-build" updating username or path as needed. This should be wherever your settings and builds are stored by Sublime Text.

Make sure the file is open and selected in Sublime Text. Now, when you press Cntrl + B to build and run it, it will open another tab, titled "REPL [python]", executing and displaying the results of your python code.

If you would like to go a step further, I highly recommend making the follow changes, to allow Sublime to reload your executed python in the same window, when you press Cntrl+B (Build), instead of it opening a new tab each time:

And to add on to the already solved problem, I had installed Portable Scientific Python on my flash drive E: which on another computer changed to D:, I would get the error "The system cannot find the file specified". So I used parent directory to define the path, like this:

Written by a Google engineer sublime text is a cross-platform IDE developed in C++ and Python. It has basic built-in support for Python. Sublime text is fast and you can customize this editor as per your need to create a full-fledged Python development environment. You can install packages such as debugging, auto-completion, code linting, etc. There are also various packages for scientific development, Django, Flask, and so on.

Settings are accessed via the Preferences Settings menu item. Theleft-hand pane contains all of the default settings, along with a descriptionof each. The right-hand pane is where customization can be saved.

User Interface Settings: These settings affect the general userinterface, across all open windows. Examples include the theme,animation_enabled and overlay_scroll_bars. These settings arepresented in the second section of the default settings file.

Application Behavior Settings: These settings affect the behavior of theapplication, across all open windows. Examples include the hot_exit,index_files and ignored_packages. These settings are presented in thethird section of the default settings file.

The User Interface Settings and Application Behavior Settings are global to theentire application and can not be controlled by a syntax specific settings file,nor the settings key in a .sublime-project.

The name of each .sublime-settings file determines its purpose. Names can be descriptive (like Preferences (Windows).sublime-settings or Minimap.sublime-settings), or they can be related to what the settings file is controlling. For example, file type settings need to carry the name of the .tmLanguage syntax definition for the file type. Thus, for the .py file type, whose syntax definition is contained in Python.tmLanguage, the corresponding settings files would be called Python.sublime-settings.

Unless you need very fine-grained control over settings, you can access the main configuration files through the Preferences Settings - User and Preferences Settings - More menu items. Editing Preferences Settings - Default is discouraged, because changes will be reverted with every update to the software. However, you can use that file for reference: it contains comments explaining the purpose of all available global and file type settings.

The same settings file (such as Python.sublime-settings) can appear in multiple places. All settings defined in identically named files will be merged together and overwritten according to predefined rules. See merging-and-order-of-precedence for more information.

In addition to settings files, Sublime Text maintains session data, which is configuration for the particular set of files being currently edited. Session data is updated as you work on files, so if you adjust settings for a particular file in any way (mainly through API calls), they will be recorded in the session and will take precedence over any applicable .sublime-settings files.

Finally, it's also worth noting that some settings may be automatically adjusted for you. Keep this in mind if you're puzzled about some setting's value. For instance, this is the case for certain whitespace-related settings and the syntax setting.

If you want to target a specific file type, name the .sublime-settings file after the file type's syntax definition. For example, if our syntax definition +was called Python.tmLanguage, we'd need to call our settings file Python.sublime-settings.

Python has become one of the most popular programming languages in recent years. There is no doubt that python offers remarkable features for development in areas such as Artificial intelligence, neural networking, big data etc. To take full advantage of these features, the use of an ideal code editor is very crucial. One such exceptional code editor for python is Sublime Text.

In this article, we will look at a step-by-step guide for how to setup Sublime Text for full stack Python development, how to use many of the commands, features, and keyword shortcuts that make Sublime text a powerful tool and how you can enhance some of the basic functionalities using different packages.

Sublime Text is a lightweight, cross-platform code editor mostly popular for its speed, simplicity, ease of use, and robust community support. It is an incredible code editor out of the box even without any add-ons or customizations. Still, the add-on packages and custom settings can be a great level up as it introduces various new features that can significantly enhance the functionalities. The rich package ecosystem offered by sublime text makes it very easy to configure the text editor specifically for what you want to use it for. Some of the packages are universally helpful and improve the ease of use whereas, some are very specific to a field of development.

By default, sublime text can be used with any programming language but its support for Python is considered one of the best. Keep reading below for a complete guide on how to use Sublime Text for Python.

It only takes these three words to conclude the reason for choosing Sublime Text for Python development, simplicity, Interface and customization. All the features offered by sublime text are targeted at improving the interface and as a result, it makes the code editor extremely simple. On top of that its extensive customizable options make it the ideal choice for a code editor.

Being a lightweight code editor, Sublime Text is extremely fast. The creators have also emphasized keeping the experience smooth and simple. The code editor just pops up right away when opened, unlike various other IDEs that take a significant amount of time to boot up and then welcome you with a bombardment of messages and prompts.

Its also autosave features also keep things very simple as you can just leave your work and next time it will open up from exactly where you left off so you will not have to worry about saving your work in case of a low battery or sudden power off.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages