Question:
I am trying to create a python script for automating some of my personal stuff. In the script, I first want to activate my virtual environment and then do some other tasks, (API calls and processing them). But in thescript.py
the command that is responsible for activating the virtual environment is not working.
I have triedAnswer:
Looks like this answer I linked doesn’t work for Python 3, but in the comments for the answer in that post I found the following from @Calimo which worked for me:subprocess
without specifying the correct environment. By default subprocess
spawns a new process using the global environment. Specify the desired virtual environment by providing the env
arg when calling subprocess
, ex after activating the virtual environment with the code above:If you have better answer, please add a comment about this, thank you!