Related
Okay, I've looked through a bunch of python venv with sublime text questions, and I'm pretty sure this issue is due to the specifics of venv on windows.
I'm on Windows, using Python 3.10, and the virtualenv package to manage my virtual environments.
I'm trying to set up a custom build in a Sublime project file that does the following:
activate the venv for the local project
echos the VIRTUAL_ENV to the shell to show the correct venv has been activated
I've been having issues with getting both into one build command, so here's the current array with the two steps as seperate builds:
"build_systems":
[
{
"name": "activate",
"cmd": "$project_path/venv/Scripts/activate.bat",
"shell": true
},
{
"name": "Current VENV?",
"cmd": "echo %VIRTUAL_ENV%",
"shell": true
},
]
Currently, when I run the activate build, I get the following:
The system cannot find the path specified.
[Finished in 80ms with exit code 1]
[cmd: C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat]
[dir: C:\Users\kreeh\Repos\project]
If I run C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat in a separate cmd.exe window, it correctly activates the venv, and when I print the %VIRTUAL_ENV% var, it correctly returns the venv location.
C:\Users\kreeh>C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat
(venv) C:\Users\kreeh>echo %VIRTUAL_ENV%
C:\Users\kreeh\Repos\project\venv
I assume this is an issue with how the Sublime Text build system is handling the windows path formatting. If I try and utilize the working directory param, it doesn't work, because the cmd.exe doesn't do relative paths nicely.
{
"name": "activate",
"cmd": "venv/Scripts/activate.bat",
"working_dir": "${project_path}",
"shell": true
},
returns
'venv' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 60ms]
So, is there a way to have the Sublime Build system handle the windows path correctly, or is there a way to use a relative path in the cmd?
#MattDMo pointed out the flaw in my logic, which is that the venv activation doesn't actually do anything in and of itself -- it changes the python interpreter used for future commands in that prompt window. As such, it's kind of a useless thing for a build system. Instead, I added a venv-specific pip install and build commands so far.
{
"build_systems":
[
{
"name": "pip install",
"cmd": "${project_path}/venv/Scripts/pip3.exe install -r requirements.txt ",
"working_dir": "${project_path}",
"shell": true
},
{
"name": "VENV Build",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"cmd": "${project_path}/venv/Scripts/python.exe $file",
"shell": true,
},
],
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
],
One thing to note, as a Windows user, I had to add the follow_symlinks=true to the folders list -- this is because the way venv works on windows (or at least on MY install), there's not an actual python.exe in that venv folder, it's a symlink.
I'm trying to get Sublime Text 3 to run a Python script. A simple two liner
var = raw_input("Enter something: ")
print("You entered " + var)
which asks for input, waits for it, then prints it out in windows console prompt.
Seeing the number of similar questions on the site, this is a problem for quite a number of users, so I went through those and tried ... stuff. Made a copy of exec.py file, commented that one line, made a new pythonw build file, tried messing about with the build file ... nothing seems to work.
In lack of a definite solution, how do you work with input using Sublime Text?
Sublime Text on its own cannot handle input via raw_input() (Python 2) or input() (Python 3). The same is true of other languages as well - Ruby's gets, Java's Scanner class, Node's readline class, scanf in C, cin in C++, etc. One short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL. It may require some configuration of the Main.sublime-menu files to get your preferred interpreter to run properly. Alternatively, you can use the excellent Terminus plugin - details are at the bottom.
If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build:
Windows
{
"cmd": ["start", "cmd", "/k", "c:/python38/python.exe", "$file"],
"selector": "source.python",
"shell": true,
"working_dir": "$file_dir",
"env": {"PYTHONIOENCODING": "utf-8"}
}
changing the path to your Python executable as appropriate. Then, go to Tools -> Build System and select Python_cmd, and when you hit CtrlB to build, a new cmd window will open up with your file running. The /k option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.
Please note that this build system is Windows-specific, as macOS and Linux do not have cmd. Build systems for those platforms are below.
macOS
If you are running OS X/macOS, the following build system will open your program in a new instance of Terminal. Save it as Packages/User/Python_Terminal.sublime-build. In my testing on macOS 10.15, the Terminal window didn't always come to the top when activated, so if you may need to look for it behind other windows.
{
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
You may need to specify the path to your Python executable if it's not on your $PATH.
Linux
And finally, here is a build system for Linux. It was tested on Ubuntu, so if you use another distribution you'll need to ensure that gnome-terminal is installed. Save it as Packages/User/Python_shell.sublime-build. Once the program has finished running, hit any key to close the window.
{
"shell_cmd": "gnome-terminal --working-directory=$file_path -- bash -c 'python3 -u \"$file\" && read -n 1 -s -r'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
For reference, the Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages or ~/.config/sublime-text/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages or ~/Library/Application Support/Sublime Text/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages or C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages InstallationFolder\Sublime Text\Data\Packages
The exact path depends on version and whether or not you upgraded from Sublime Text 3.
I have only tested these build systems with Python, but they should work fine for any language. When modifying, just make sure that all the single and double quotes match up – you'll get errors or unexpected behavior if they don't.
UPDATE
There is a platform-independent plugin called Terminus that, among other things, provides a drop-in replacement for the default exec build system engine. It allows you to interact with your program in the build panel below your code. Once you've installed it from Package Control, create the following build system (again, for Python):
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"cmd": [
"/path/to/python", "-u", "$file"
],
"working_dir": "$file_path",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
}
You'll need to adjust the path to your Python executable, as above. Make sure you read the documentation to find out all the other ways you can make use of this great plugin.
To add on to the answer from Shritam Kumar Mund, to make a key binding for this:
{ "keys": ["alt+k", "alt+k"], "command": "repl_open", "args": {"cmd":
["python", "-u", "$file_basename"], "cwd": "$file_path", "encoding":
"utf8", "extend_env": {"PYTHONIOENCODING": "utf-8"}, "external_id":
"python", "syntax": "Packages/Python/Python.tmLanguage", "type":
"subprocess"}},
I found this by using the following in the console:
sublime.log_commands(True)
Sublime Text does not support inputting data into a program. For working with inputs you need to install a package called SublimeREPL.
Follow this:
open Sublime Text >> CTRL + P
CTRL + P will open the Package control
Click on Package Control: Install package
Wait for a sec to pop up a search bar.
Type SublimeREPL and Click it.
It'll get installed in a few secs.
Then follow the following steps to run your program;
Tools >> SublimeREPL >> Python >> Python run Current File
It'll open a new window, where you can give your input and get the output.
You can use this sublime_build file which make run on cmd when you press ctrl+B .
Just go to tool ->sublime build->new build system and paste the below given as it is;
I have personally edited this sublime build file with my experience and believe me it has some good functionalities:
color changing when program terminates or ends
interactive output and input
console window automatic opening
pause after program finishes and wait till enter
{
"cmd":["start", "cmd", "/c" ,"python $file && color b0 && pause"],
"selector": "source.python",
"working_dir": "${file_path}",
"file_regex": "(.+):(\\d+): error: ",
"shell": true
}
Thanks #MattDMo for the answer, which doesn't require installing any plugin. But after I tried the command in macOS:
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
I find it seems to run from background every time, which is not convenient.
So I tried another method: to use a temp.sh to run. Here is the command:
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
This method will pop up a new window to the front, and it should be feasible on other platforms after a small modification, but I didn't try.
here is the full content in "python_input.sublime-build":
{
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
}
I'm trying to get Sublime Text 3 to run a Python script. A simple two liner
var = raw_input("Enter something: ")
print("You entered " + var)
which asks for input, waits for it, then prints it out in windows console prompt.
Seeing the number of similar questions on the site, this is a problem for quite a number of users, so I went through those and tried ... stuff. Made a copy of exec.py file, commented that one line, made a new pythonw build file, tried messing about with the build file ... nothing seems to work.
In lack of a definite solution, how do you work with input using Sublime Text?
Sublime Text on its own cannot handle input via raw_input() (Python 2) or input() (Python 3). The same is true of other languages as well - Ruby's gets, Java's Scanner class, Node's readline class, scanf in C, cin in C++, etc. One short-term solution is to get Package Control if you don't already have it, then install SublimeREPL. It allows you to transfer or run part or all of your code through the running REPL. It may require some configuration of the Main.sublime-menu files to get your preferred interpreter to run properly. Alternatively, you can use the excellent Terminus plugin - details are at the bottom.
If the code you're running doesn't play well with SublimeREPL (for instance, you're using C/C++/Java/etc. and need to compile code before it runs), or you just want to run it independently of Sublime, you'll need to make your own build system. Save the following as Packages/User/Python_cmd.sublime-build:
Windows
{
"cmd": ["start", "cmd", "/k", "c:/python38/python.exe", "$file"],
"selector": "source.python",
"shell": true,
"working_dir": "$file_dir",
"env": {"PYTHONIOENCODING": "utf-8"}
}
changing the path to your Python executable as appropriate. Then, go to Tools -> Build System and select Python_cmd, and when you hit CtrlB to build, a new cmd window will open up with your file running. The /k option returns to the command prompt, without closing the window, after your program is done running so you can examine output, tracebacks, etc.
Please note that this build system is Windows-specific, as macOS and Linux do not have cmd. Build systems for those platforms are below.
macOS
If you are running OS X/macOS, the following build system will open your program in a new instance of Terminal. Save it as Packages/User/Python_Terminal.sublime-build. In my testing on macOS 10.15, the Terminal window didn't always come to the top when activated, so if you may need to look for it behind other windows.
{
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
You may need to specify the path to your Python executable if it's not on your $PATH.
Linux
And finally, here is a build system for Linux. It was tested on Ubuntu, so if you use another distribution you'll need to ensure that gnome-terminal is installed. Save it as Packages/User/Python_shell.sublime-build. Once the program has finished running, hit any key to close the window.
{
"shell_cmd": "gnome-terminal --working-directory=$file_path -- bash -c 'python3 -u \"$file\" && read -n 1 -s -r'",
"working_dir": "$file_path",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}
For reference, the Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages or ~/.config/sublime-text/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages or ~/Library/Application Support/Sublime Text/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages or C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages InstallationFolder\Sublime Text\Data\Packages
The exact path depends on version and whether or not you upgraded from Sublime Text 3.
I have only tested these build systems with Python, but they should work fine for any language. When modifying, just make sure that all the single and double quotes match up – you'll get errors or unexpected behavior if they don't.
UPDATE
There is a platform-independent plugin called Terminus that, among other things, provides a drop-in replacement for the default exec build system engine. It allows you to interact with your program in the build panel below your code. Once you've installed it from Package Control, create the following build system (again, for Python):
{
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
"cmd": [
"/path/to/python", "-u", "$file"
],
"working_dir": "$file_path",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
}
You'll need to adjust the path to your Python executable, as above. Make sure you read the documentation to find out all the other ways you can make use of this great plugin.
To add on to the answer from Shritam Kumar Mund, to make a key binding for this:
{ "keys": ["alt+k", "alt+k"], "command": "repl_open", "args": {"cmd":
["python", "-u", "$file_basename"], "cwd": "$file_path", "encoding":
"utf8", "extend_env": {"PYTHONIOENCODING": "utf-8"}, "external_id":
"python", "syntax": "Packages/Python/Python.tmLanguage", "type":
"subprocess"}},
I found this by using the following in the console:
sublime.log_commands(True)
Sublime Text does not support inputting data into a program. For working with inputs you need to install a package called SublimeREPL.
Follow this:
open Sublime Text >> CTRL + P
CTRL + P will open the Package control
Click on Package Control: Install package
Wait for a sec to pop up a search bar.
Type SublimeREPL and Click it.
It'll get installed in a few secs.
Then follow the following steps to run your program;
Tools >> SublimeREPL >> Python >> Python run Current File
It'll open a new window, where you can give your input and get the output.
You can use this sublime_build file which make run on cmd when you press ctrl+B .
Just go to tool ->sublime build->new build system and paste the below given as it is;
I have personally edited this sublime build file with my experience and believe me it has some good functionalities:
color changing when program terminates or ends
interactive output and input
console window automatic opening
pause after program finishes and wait till enter
{
"cmd":["start", "cmd", "/c" ,"python $file && color b0 && pause"],
"selector": "source.python",
"working_dir": "${file_path}",
"file_regex": "(.+):(\\d+): error: ",
"shell": true
}
Thanks #MattDMo for the answer, which doesn't require installing any plugin. But after I tried the command in macOS:
"shell_cmd": "osascript -e 'tell app \"Terminal\" to do script \"cd $file_path && python3 -u $file\"'",
I find it seems to run from background every time, which is not convenient.
So I tried another method: to use a temp.sh to run. Here is the command:
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
This method will pop up a new window to the front, and it should be feasible on other platforms after a small modification, but I didn't try.
here is the full content in "python_input.sublime-build":
{
"cmd": ["zsh", "-c", "echo \"python3 ${file}\" > /tmp/tmp.sh ; chmod +x /tmp/tmp.sh ; open -a Terminal /tmp/tmp.sh ; sleep 2 ;rm /tmp/tmp.sh"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
}
So I've installed anaconda to a directory I have privileges for but I can't get sublime text 3 to recognise that the shell is now using anaconda python:
>which python
/local/home/USER/Apps/anaconda/bin/python
when I build with sublime launched from the same shell:
import astropy
print astropy.__file__
it gives a different directory: /soft/python-SL7/lib/python2.7/site-packages/astropy/init.pyc
My .tcshrc file reads:
setenv PATH /local/home/USER/Apps/anaconda/bin:${PATH}
alias subl /local/home/USER/Apps/sublime_text_3/sublime_text
My .bashrc (not that it should be using it) reads:
export PATH="/local/home/sread/Apps/anaconda/bin:$PATH"
Any ideas?
The easiest way is to create a new build system that points to your Anaconda installation. Create a new file in Sublime with JSON syntax and the following contents:
{
"cmd": ["/local/home/USER/Apps/anaconda/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Save the file in your Packages/User directory (should be ~/.config/sublime-text-3/Packages/User) as Anaconda.sublime-build. Finally, select Tools → Build System → Anaconda, and when you hit CtrlB in a Python file it should now run using Anaconda.
If you want to set up SublimeREPL to use Anaconda with IPython in Sublime, you can follow the instructions here to set up the proper menu option (altering the path to suit your environment, of course), and my gist here for setting up SublimeREPL for IPython 4 and Jupyter.
The other answer is correct, but you can also have a per project setting by editing the project file and adding this:
"build_systems":
[
{
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"name": "Anaconda Python Builder",
"selector": "source.python",
"shell_cmd": "\"python3\" -u \"$file\""
}
],
This also has the advantage of not leaving too many build systems in the build menu.
I am using sublime text 2 for python development along with virtualenv!
The standard sublime text 2 build system uses the standard python install rather than my virtualenv where my packages are installed.
How can I get sublime text 2 to build using my virtualenv?
I currently use the terminal to activate my environment and run my scripts.
UPDATE: Never got it working, but seeing as i am using flask and it builds when you make a change, it's not a big issue
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.
I'm using Flask, but I think it's apply to nearly every case.
My actual build is like this, where "benicio" is the directory of my project:
{
"cmd": ["source ~/projs/benicio/venv/bin/activate && python ~/projs/benicio/benicio_tests.py"],
"shell": true
}
Sorry to add yet another answer to this - but this caused me a large amount of grief figuring this out.
Not only do you need to make a build system like:
"build_systems":
[
{
"name": "Maths",
"env": {"PYTHONPATH":"/home/nebffa/Desktop"},
"path":"$project_path/bin",
"cmd": ["$project_path/bin/python3.3", "-u", "$file"]
}
]
but you HAVE to change a setting in Sublime Text - go to Tools --> Build System --> "Maths". In my case I need to choose "Maths" because that's what I named my build system. If you don't do this - Sublime Text does not use your build system!!
I have just got sublime text 3 to working in a virtualenv. Although the OP specified ST2, there all likely more like myself who are using ST3. Thanks to user1248490 and Russell Beattie I arrived at the following:
{
"shell_cmd": "$project_path/vi_sys_pkgs/bin/python3 -u \"$file\"",
"path": "$project_path/vi_sys_pkgs/bin",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Note that "cmd" is now "shell_cmd" in ST3. See ST3 blog
Under MAC OSX, this works for me
{
"cmd": ["/your/virtualenv/bin/python", "-u", "$file"]
}
What i did was keep it simple:
Went to root drive and created python folder:
sudo mkdir python
then went in there and created the virtualenv
virtualenv --no-site-packages virtualenvname
then created a newbuild in ST2 with the above command and it works
This is what I have as a build system (assuming my virtualenv is created as a folder called 'env' in my current project directory). This at least means I don't need to constantly change the build system between projects:
{
"cmd": ["env/bin/python", "-u", "$file"]
}
I saved this as a New Build System (Tools -> Build System -> New Build System).
I use this to build my Flask project. I have added the following code to my Project Settings: Project -> Edit Project
{
"folders":
[
{
"path": "/C/MyDev/chilinzb/"
}
],
"build_systems":
[
{
"name": "Flask",
// activate the specific virtualenv for the project
"cmd": ["C:/MyDev/virtualenvs/env_chilinzb/Scripts/python", "$file"]
}
]
}
and then I just switch to my run.py file and hit Ctrl+B
this combination worked great:2 steps
1) add the 2 appropriate keys to the 'env' key.
A) DJANGO_SETTINGS_MODULE
B) PYTHONPATH
2) update cmd to reflect the version of python you want to use.
{
"env":{"DJANGO_SETTINGS_MODULE":"my_project.settings",
"PYTHONPATH":"d:\\Projects\\virts\\my_project\\Scripts;d:\\Projects\\virts\\my_project\\Lib;d:\\Projects\\virts\\my_project\\Lib\\site-packages;D:\\Projects\\my_project"
},
"cmd": ["c:/Python27/python.exe","$file"]
}
I have an answer for anyone who uses Heroku and uses their foreman tool, and it works great. Simply create a new build system like so:
{
"cmd": ["foreman", "run", "python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
This pulls in all of the environment variables available to Foreman, including your virtualenv's $PATH variable, which adds the virtualenv Python to your python path.
source did not work for me inside the build on lubuntu.
use '.' or dot instead of 'source'.
this did work:
{
"env": {
"DJANGO_SETTINGS_MODULE":"django_project_name.settings",
"PYTHONPATH":"/home/my_username/current/django_project_name:/home/my_username/.virtualenvs/django_project_name/lib/python2.7:/home/my_username/.virtualenvs/django_project_name/lib/python2.7/site-packages/"
},
"working_dir":"$project_path",
"cmd":[". /home/my_username/.virtualenvs/django_project_name/bin/activate && python $file"],
"shell":true
}
this worked for me:
{
"cmd": ["C:/Users/user/virtualenvs/env1/Scripts/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
saved build in:
"C:\Users\user\AppData\Roaming\Sublime Text 2\Packages\User\"
as
"Python_env1.sublime-build"
Select
Tools> Build System> Python_env1
done!
using windows 8.1, st2
Assuming you keep your project-specific virtualenv in an .env-folder on the top level of your project.
Sublime > Project > Save project as... (if you haven't already. This will allow you to set custom build options for the project
Project > Edit Project:
{
"folders":[
{
"path": ".",
"folder_exclude_patterns": [".env"],
}
],
"build_systems":[
{
"name": "Run in VirtualEnv",
"shell_cmd": "source $project_path/.env/bin/activate && python -u $file"
}
]
}
Tools > Build System > Run in VirtualEnv
Tools > Build
Please note that this was tested with Sublime Text 3.
Note comments about this solution being incorrect.
You have to edit your sublime-project file and add the following:
"build_systems":
[
{
"name": "Run Tests",
"cmd": ["source", "/path/to/your/virtualenv/bin/activate"],
"working_dir": "/path/to/to/you/django_project",
"cmd": ["python", "manage.py", "test"]
}
]