use conda environment in sublime text 3

NOTE: This will work for virtual environments created with conda as well as venv or virtualenv, you just need to activate it first to find the path to the python[3] executable.

A standard Python .sublime-build file looks like this:

{
    "cmd": ["/path/to/python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

All you need to do to use a particular conda environment is modify the path to the python or python3 executable within the environment. To find it, activate your environment and type (depending on the version you’re using)

which python

or

which python3

on Linux/macOS, or

where python

on Windows, then copy the path into your custom .sublime-build file. Save the file in your Packages/User directory, then make sure you pick the right one via Tools -> Build System before building.

Leave a Comment