Using virtualenv with sublime text 2 Using virtualenv with sublime text 2 python python

Using virtualenv with sublime text 2


You can also set the path for the build system to the bin directory of your virtualenv, like so:

"build_systems":[    {        "selector": "source.python",        "env": {"PYTHONPATH":"/Users/user/project"},        "path":"/Users/user/work/myvirtualenv/bin:$PATH",        "name": "Run virtualenv python",        "cmd": ["python", "-u", "$file"],        "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",        "variants": [            {   "name": "Run all Tests",                "working_dir": "/Users/user/project",                "cmd": ["nosetests"]            }         ]    }]

This also allows other tools, like nose in the example, to find the correct python binary from the virtualenv.


In windows this works for me:

"build_systems":[    {    "name": "Run Tests",    "working_dir": "/path/to/to/your/django_project",    "cmd": ["/path/to/your/virtualenv/bin/python.exe", "manage.py", "test"]    }]


Sublime's Build System supports variables which can be used with Sublime project files to make this a bit more portable across projects.

If your virtual environments are in a standard spot, create a new project file (Project -> Save Project As) into the root directory of your project just above your virtual environment directory. Then create a new build file with something like this:

{    "cmd": ["$project_path/venv/bin/python", "-u", "$file"]}

It seems to then pick up the rest automatically - the same as if you typed ./venv/bin/python from the command line - no need to mess with paths, environment variables, etc.