Lets assume a I've a dict of venv and the path to the activate.bat files.
{"env": "C:\\Users\\basic\\Projects\\some\\env\\Scripts\\activate.bat",
"test": "C:\\Users\\basic\\python_virtual_envs\\Test\\actiavte.bat"}
Now the user is allowed to input the name of the env they want to activate, and I want a function that can activate this venv.
The code that I've so far. (That does not work)
import subprocess
def activate_venv(path: str) -> None:
subpocess.run(path, shell=True)
paths = {"env": "C:\\Users\\basic\\Projects\\some\\env\\Scripts\\activate.bat",
"test": "C:\\Users\\basic\\python_virtual_envs\\Test\\activate.bat"}
env_name = input("Enter the name of the venv you want to activate: ")
activate_venv(paths[env_name])
Related questions I've found
Activate a virtualenv with a Python script The OP is exactly what I'm looking for but none answers makes sense, all the answers are targeted in running a python script
using a venv. I'm not looking for, running a python script using a venv, I just want to activate the venv.