Sublime Forum

How to activate projects virtual env automatically when using TerminalView in project

#1

I would like to automatically have activated my virtual env when I open a BASH shell (via TerminalView) in a project - a solution similar to Pycharms IDE.

My OS is linux-based. I’m using python’s Django in making web-app’s where I use the BASH shell a lot (running the local server, activating Django shell etc.). I use the TerminalView plugin to open a BASH shell. In the BASH shell I type in this to activate my virtual env:

source /home/jesper/code_u/tavler_simple_complex/venv/bin/activate venv

Switching between projects this task is becoming a little heavy for me. I tried to make macro’s in ST3, but it does not work in TerminalView.
I am therefore looking for a solution where the TerminalView knows which virtual env to activate from the settings in the current project. And then activates it automatically when I open a BASH shell.

My ‘.sublime-project’-files and the ‘TerminalView.sublime-commands’-file are looking like this:

‘.sublime-project’-file:

{
	"build_systems":
	[
		{
			"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
			"name": "Anaconda Python Builder",
			"selector": "source.python",
			"shell_cmd": "\"python\" -u \"$file\""
		}
	],
	"folders":
	[
		{
			"path": "/home/jesper/code_u/tavler_simple_complex"
		}
	],
	"python_interpreter": "/home/jesper/code_u/tavler_simple_complex/venv/bin/python3"
}

The code snippet for ‘Open Bash shell’ in the’TerminalView.sublime-commands’-file

{
    "caption": "Terminal View: Open Bash Terminal",
    "command": "terminal_view_open",
    "args"   : {"title": "Terminal (bash)", "cmd": "/bin/bash -l"},
},

Any suggestions are appreciated

0 Likes

#2

I’ve seen this question before. Did you cross post this - almost verbatim - to Stack Overflow? I don’t know if you did them both at the same time, or went to one after getting zero from the other, (and I am not taking the time to look) but if so, you got ZERO help from both sites. Am I right? Was that you?

My problem is close but not identical. I can’t get the venv (not pipenv, and not virtualenv) back for running scripts in sublime itself. I don’t even know how or when it got lost / broken / overwritten.

How sad is it that? And if folks out there ignored it because the answer is ‘obvious’, would you be so kind as to tell us where to find this obvious answer?

0 Likes