How to: Add Conda Environments to SublimeREPL builds

Post a Comment
Hope you are doing good, this is going to a bit long process but hang tight. As you might already know, Sublime is 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 following things:
  • Installing SublimeREPL package through Package Control
  • Creating environments using Conda
  • Editing SublimeREPL settings for adding environment.
  • Adding build files and connecting build to added environments.
  • Testing out files using builds.
Lot to cover, but if you haven't yet installed or already using sublime, then go ahead and install sublime. Its a great light weight text editor out there.

Installing SublimeREPL Package

Ok, so we'll start off with installing 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 has various packages, among which we are going to install SublimeREPL package specifically. For that we will be selecting install package option in 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 like ability for our sublime & also allows us to take input required for programs/codes within sublime.


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

Creating environment using Conda

Here we will create a environment for our project work. You have liberty to choose any virtual environment creating tool for this, but at 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.


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:
conda create -n test-env python=3.6


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 python binary of our environment. for that we'll be opening up sublime and going to Preferences > Browse Packages.
  2. This end up opening a directory with 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 fileup, 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": "Python - (test_env)",
                     "id": "test_env_python",
                     "mnemonic": "R",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["C:\\Users\\CG-DTE\\Anaconda3\\envs\\test-env\\python", "-i", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
 },
in above code, we have to
  1. add value to key "cmd". the value is a list in which first value will be our python binary env path. also -i instead of -u, this will add interactivity for you 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 - this also you can name as near to environment name. i'm naming it test_env_python. (we will use this during next sublime build creation process)

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 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 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)

Testing Python files with Build

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



and that's it, now pretty much you can add any number of environments in sublime by following above process. your patience well paid.

Y Aakash
Hello World, I Dwell with Creative Sketching, Coding, Finance & Blogging by putting my Views and Work.

Related Posts

Post a Comment