Sublime Forum



Hi folks,

in the past days I’ve written a solution to run my code (e.g. test cases) thru my virtual environments under OSX. This involves several scripts:

  • A wrapper to add support for wrapping for example the build commands to load a proper environment (necessary on OSX).
  • Small wrapper to run within a login shell.
  • Script to run a Python file thru a virual environment (virtualenv) if possible otherwise directly. Currently only supported within UNIX environments. Plz send me patches for Windows environmnts and I will implement it properly.

For this to work, I’ve set up a special folder ~/Code/env/ which contains all my virtual environments. I create an environment for each project I work on for some time in a separate folder (e.g. ~/Code/env/example_project/). I’m also using Mercurial and place every repo in ~/Code/hg/. After that I create a special project folder within ~/Code/ (e.g. ~/Code/example_project). Finally I symlink all my necessary repos into the project folder. When not using a project folder, I name my virtualenv folder like my repo folder so that they match by folder name. tries to use the CODE_ENV environment variable to find the envs therefore I’ve set it to ~/Code/env within my .bashrc.
After this should already be able to launch a Python file within the desired environment. You can test it by running e.g. “ ~/Code/example_project/” which then should print out a line beginning with an ampersand which shows what is being run. There you should see something like “$ source ~/Code/env/example_project && ~/Code/example_project/” and what it outputs.

The last part is getting to run within Sublime Text 2 and making it to use to load the proper environments (shell and Python). For that I’ve placed my sublime_plugins repo into “~/Library/Application Support/Sublime Text 2/Packages/” so that Sublime recognizes the module. This module extends the init method of the AsyncProcess class of the supplied in order to make it possible to add the wrapper for our build scripts. The extensions tries to read the “exec_arg_list_wrapper” setting from the “Global.sublime-settings” file. Create one in your User folder and set it to the absolute path of the (read the file header of on how that works). Now you should be able to “build” a Python file via the build menu and see that it loads the proper environment before it finally executes it.

You can get the files from here:

Have fun,


Open Python files from selection or current line


do you and example of that?

I tried but I couldn’t manage to make it work.