I’m writing some python to render stuff that I tweak and run a lot, and that runs inside a virtual env. I would like a keyboard command to run a bash script (that launches python) inside the known terminal and virtual env.
I played a bit with setting up a shell script and a custom task, but entering the virtual env is always a bit tricky.
I don’t need a debugger or anything complicated, just a way to run the python code and attach a keystroke to it.
https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
https://code.visualstudio.com/docs/python/jupyter-support-py
2
Answers
You can just run the
python.exe
/python
binary in the virtualenv folder as an executable.So to run a specific python file with a virtual environment:
For Windows it would be
.path_to_virtualenvScriptspython.exe yourfile.py
, and for Unix system it would be./path_to_virtualenv/bin/python yourfile.py
And instead of running a python file, you can probably pipe the input command into the python executable in the path above if you want to run a specific python command.
So something like
COMMAND | ./path_to_virtualenv/bin/python yourfile.py
Could you please explain the difference between the way you want and the following operation:
I think there is no difference because before your using a keyboard command, you still need to choose the interpreter.
By the way, use jupyter notebook or interactive window will be a good chioce as well.