I hope you are doing good, we’ll look at SublimeREPL & this is going to be a bit long process but hang tight. As Sublime is a text editor for many people’s choice for coding, I assume that you either recently switched to sublime or just looking for this method for lighter work of programming. Have no worries, I got you covered. Here we will explore the following things:

A lot to cover, but if you haven’t yet installed or already using sublime, then go ahead and install sublime. It’s a great lightweight text editor out there.

Installing SublimeREPL package

Ok, so we’ll start off with installing the SublimeREPL package. Follow with me, by going to Preferences in the navigation bar. And selecting package control. (no package control? go here and install it.)

package-control

Package control has various packages, among which we are going to install the SublimeREPL package specifically. For that, we will be selecting the install package option in package control.  

installing-package-from-package-control

Doing that, will open up listing of various packages available to for us to install, but by not getting overwhelmed by all of them. we’ll focus on a specific package of SublimeREPL, which adds a interpreter likeability for our sublime & also allows us to take input required for programs/codes within sublime.  

sublimerepl-package
Sublime REPL package

Clicking that package will automatically start the download for the package, make sure you have a working internet connection prior to this process. Further steps will explain creating a conda environment and editing the SublimeREPL setting.

Creating an environment using Conda

Here we will create an environment for our project work. You have the liberty to choose any virtual environment creating a tool for this, but in the end, all you need is a path to to your virtual environment. I’m using conda here provided with anaconda. lets dive. Now, by doing a conda env list you can see currently I have a base/root env, except that I have no environment what so ever.  

listing-conda-environments
Conda env list

Now, creating a conda environment , we’ll be calling that test-env, because lets face the vibe of uncreativity a bit.  

Command to create env (change version of python as ur need ):

 conda create -n test-env python=3.6
new-conda-environment
New Conda Environment

We’ll be using that environment location mentioned. Specifically the path to python binary inside that environment is needed. copying that to our clipboard. Adding environment to Sublime REPL

  1. Now that we are ready with our environment, all is left to link our build with the python binary of our environment. for that, we’ll be opening up sublime and going to Preferences > Browse Packages.
  2. This ends up opening a directory with a bunch of packages of sublime living in mess. Out of that, we need to enter into SublimeREPL > config > Python directory.
  3. doing that will show up Main.sublime-menu in which we have to add environment path.

when you open that file up, it kinda looks like JSON stuff, here all we have to do is add a snippet of code into that file having environment path with python binary.

{"command": "repl_open",
 "caption": "NAME OF YOUR ENV",
 "id": "test_env_python",
 "mnemonic": "R",                     
 "args": { "type": "subprocess", 
          "encoding": "utf8",
          "cmd": ["PATH TO ENV PYTHON INTERPRETER", "-i", "$file_basename"],
          "cwd": "$file_path",
          "syntax": "Packages/Python/Python.tmLanguage",   
          "external_id": "python",    
          "extend_en,v": {"PYTHONIOENCODING": "utf-8"}
} }, 

in the above code, you have to add some values:

  1. Add value to key “cmd”. the value will be a list in which the first value will be our python binary env path. Also -i instead of -u, this will add interactivity for your namespace.
  2. In “caption” key’s value – You can name anything that you can remember near to env name, I’m naming it…   Python – (test_env)
  3. In “id” key’s value – you can name as near to environment name. I’m naming it test_env_python. (we will use this during the next sublime build creation process)
adding-build-code
Add Build Code

Creating Build Files in Sublime

We are almost there, keep on hanging. Next up we will create a build, to build our program files with the environment we just created moments ago.

Goto Tools > Builds System > New Build System as the new file pops up, paste the following code snippet into that file with the value of  “id” key as previously as we saved id value in Main.sublime-menu process.  

{ "target": "run_existing_window_command",
   "id": "test_env_python",
   "file": "config/Python/Main.sublime-menu" }

Save the file as environment name, like Python(test env).sublime-build. Doing this will add a sublime build option in Tools > Build System > Python (test env)

checking-env-build
Checking Env build

Testing Python files with Build

We will test out a small code snippet of Fibonacci to test out our build of the environment. you can build a file with shortcut: Ctrl + B  

testing-sublimerepl-build
testing sublimerepl build

and that’s it, now pretty much you can add any number of environments in sublime by following the above process.

Your patience is well paid.

Helpful? Read more programming related how-to articles.