Virtual Environments, Python and Sublime 3

A simple Sublime 3-project file in order to run the currently opened script in a previously initialized virtual environment, in a linux environment:

{
  "build_systems": [
    {
      "name": "Run active script in Virtual Environment",
      "selector": "source.python",
      "shell_cmd": "source bin/activate && python '$file'",
      "working_dir": "${project_path:${folder}}"
    }
  ],
  "folders": [
    {
      "folder_exclude_patterns": [
        "bin",
        "include",
        "lib",
        "lib64",
        "__pycache__"
      ],
      "path": "."
    }
  ],
  "settings": {
    "tab_size": 4
  }
}

Save in your project’s root folder, for example, as “my-project.sublime-project”, and, when being opened, you’ll find the following Build System-entry in your Tools-menubar:

Run active script in Virtual Environment

Have fun!

Tagged with: , , , ,
Posted in Development, Python