Why SublimeText and Linux?
You want SublimeText because you do not want to wait around for laggy code-complete windows, random 2 second hitches or dealing with poor performance due to a buggy editor. Sublime opens in less than a second, it feels nearly instant. It is the fastest text editor that you can use for writing code. It opens almost immediately and performs very quick searches. SublimeText is a native app written in C++, so its footprint is much lower.
You want Linux because you do not want to deal with having to restart pc after a bit because its performance deteriorates over time.
Anaconda Distribution
-
Download Anaconda or Miniconda for linux from here.
-
Go to downloaded folder, open terminal here, type
./A
and presstab
. It will display anaconda file name on terminal../Anaconda3-2020.07-Linux-x86_64.sh
-
Follow on screen instructions. Set installation location to
/home/anaconda3/
. Dont forget to type ‘yes’ at the last.
SublimeText
Install SublimeText
Install SublimeText from package manager (pamac-manager or Add/Remove Software).
Configure Python Path
-
By default sublimetext use system’s default python which is
/usr/lib/python
. To verify this run the following code in sublimetext:import sys print(sys.path)
you will see
/usr/lib/python
which is default python libraries location.In order to make SublimeText use anaconda’s implementation of python, follow the steps.
-
open
preference-> browse package
in sublimetext, got touser
folder and create a fileanaconda.sublime-build
. Inside this file add the following line:{ "cmd":["path to python", "-u", "$file"], "file_regex": "^[ ]File \"(...?)\", line ([0-9]*)", "selector": "source.python" }
-
To find the path of anaconda python, open terminal and type:
which python
It will give the path of anaconda’s python binaries. Copy this path and paste in
“cmd”: [“paste path here”]
ofanaconda.sublime-build
file. Theanaconda.sublime-build
file will look like: -
Save it and restart sublimetext. Go to
tool-> build system
.You will see new entry calledanaconda
, select it and run the above code again. now you will see/home/zahidhasan/anaconda3/lib/python38
in the output which confirms that your sublimetext now points to the anaconda’s python.
Install Color Scheme
Install themes from package control
- Tomorrow Night
- Monokai pro
Install additional Packages
Install themes from package control
- SideBar enhancement
- A file icon
Linter
Linting is the process of checking the source code for Programmatic as well as Stylistic errors. For example, linting detects the use of an uninitialized or undefined variable, calls to undefined functions, missing parentheses, and even more subtle issues such as attempting to redefine built-in types or functions.
Install SublimeLinter
-
Press
ctr+shift+p
to open package control and selectpackage control: install package
-
Search for
SublimeLinter
and install.
Install SublimeLinter-flake8
-
Press
ctr+shift+p
to open package control and selectpackage control: install package
-
Search for
SublimeLinter-flake8
and install.
Install flake8
-
Since SublimeLinter always uses system’s library even if we’ve made SublimeText use anaconda python. So, we need to install flake8 in the system. To do this we need to disable Anaconda by renaming the folder
anaconda3
toanaconda3X
and run:pip install flake8 sud pip install flake8
-
Finally rename
anaconda3X
folder back to its default nameanaconda3
.
Configure SublimeLinter settings
Open sublime text settings. preference > package settings > sublime linter > settings
. Add the following into user setting.
// SublimeLinter Settings - User
{
"show_panel_on_save": "never",
"gutter_theme": "Packages/Theme - Monokai Pro/Monokai Pro.gutter-theme",
"styles": [
{
"mark_style": "outline",
"priority": 1,
"scope": "region.orangish",
"icon": "warning",
"types": [
"warning"
]
},
{
"mark_style": "squiggly_underline",
"priority": 1,
"scope": "region.redish",
"icon": "error",
"types": [
"error"
]
}
]
}
Kite: Auto-completion
Kite is an AI-based autocompletion tool for Python. It uses machine learning to help you with the suggestions for keywords while coding in Python. Kite will automatically install plugins for sublime text.
Troubleshooting
flake8 not found
-
Even if we’ve made SublimeText use anaconda python, SublimeLinter in SublimeText still use default python. If you see flake8 error at the status bar of sublimetext like:
That means flake8 was installed in anaconda’s library not in system’s library. Since SublimeLinter always uses system’s library, so, we need to install flake8 in system. To do this:
-
Rename the folder
anaconda3
toanaconda3X
and run:pip install flake8 sud pip install flake8
-
Rename
anaconda3X
folder back to its default nameanaconda3
. -
Run sublimetext again.
input() doesn’t work in sublimetext
SublimeText with input() function doesn’t return any output values.
To solve this problem we will use terminus
package.
-
Install
terminus
from package control. -
Go to
preference->browse package
. Insideuser
folder and create a filePython_Terminus.sublime-build
. Add the following code into this file-
For windows:
{ "target": "toggle_terminus_panel", "cmd": ["C:/Python37/python.exe", "-u", "$file"], "file_regex": "^[ ]File \"(...?)\", line ([0-9]*)", "auto_close": true, "selector": "source.python" }
NOTE: use forward slash (/) in path for windows. Append extra input() method in the source code to prevent auto close of terminus output. Setting
"auto_close": false,
disable sublimetext to execute second time unless sublimetext is restarted. -
For Linux:
{ "target": "toggle_terminus_panel", "cmd": [""\home\anaconda3\bin\python", "-u", "$file"], "file_regex": "^[ ]File \"(...?)\", line ([0-9]*)", "auto_close": true, "selector": "source.python" }
-
warning “Indentation contains tabs”
view -> Indentation -> Convert indentation to spaces