Here's what I would like to do with my Python script:
- Create virtual environment
- Change directory into environment
- Activate environment
- Install django
- Do other stuff...
I've managed to create the environment and change directory with the following:
import subprocess
import os
env_name = "env_new"
subprocess.run(["py", "-m", "venv", env_name])
chdir(env_name)
But activating the environment is a different story:
subprocess.run(["source", "./Scripts/activate"]) # Also tried with activate.bat
Result:
FileNotFoundError: [WinError 2] The system cannot find the file specified
subprocess.run([".", "./Scripts/activate"]) # Also tried with activate.bat
Result:
PermissionError: [WinError 5] Access is denied
Just to clarify, I made sure I was in the correct directory by using print(os.getcwd()).
After this I'd then like to install django. I think it has to happen inside the same run() method like so:
subprocess.run([".", "./Scripts/activate", "&&", "pip", "install", "django"]) # Or something...
Is this even possible?