Here is method to get actviate_this.py file:
Run the following commands:
pip install virtualenv
virtualenv myenv
Locate activate_this.py: After creating the virtual environment, you will find the activate_this.py file in the Scripts folder of the newly created virtual environment myenv. Copy this file to your needful virtual environment folder in something like: D:/path/to/myenv3_10/Scripts. Now you can use it.
venv_path = 'D:\\path\\to\\myenv3_10'
# Prepending the virtual environment to PATH and activating it manually
os.environ['VIRTUAL_ENV'] = venv_path
sys.path.append(os.path.join(venv_path, 'Lib', 'site-packages'))
# Activating the virtual environment using the correct path to activate_this.py
activate_script = os.path.join(venv_path, 'Scripts', 'activate_this.py')
with open(activate_script) as f:
exec(f.read(), {'__file__': activate_script})
and the file from which you want to activate virtual environment, it will have code:
import subprocess
my_process = subprocess.Popen(
[".\\myenv3_10\\Scripts\\python", "D:/path/to/other_file.py"],
shell=True
)
activate_this.pyis there for me or I didn't get something right from your question.