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.
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.)
doing this will add a sublime build option in Tools> Build System > Python (test env)
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
- 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.
- 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.
- doing that will show up Main.sublime-menu in which we have to add environment path.
in above code, we have to
{"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"}}},
- 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.
- In "caption" key's value - You can name anything that you can remember near to env name, i'm naming it.. Python - (test_env)
- 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.
save the file as environment name, like Python(test env).sublime-build{ "target": "run_existing_window_command",
"id": "test_env_python",
"file": "config/Python/Main.sublime-menu" }
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.
Post a Comment
Post a Comment