How to configure env variables with subprocess in python in Windows 10?

0

I'm trying to create a script to assist in creating virtual env with virtualenvwrapper-win in Windows 10. I've researched a lot and so far I have not found a solution to the initial settings.

First I would like to configure 'WORKON_HOME =' to create venv in the local directory of the application.

import os
import subprocess

# pegar o diretório local da aplicação: D:\Envs\MeuProject
pwd = os.getcwd()

# configurar a veriável 'set WORKON_HOME=D:\Envs\MeuProject'
subprocess.check_call(['set', 'WORKON_HOME={}'.format(pwd)], shell=True)

In this way no error occurs, but the variable is not configured for the local directory, it remains configured in the virtualenvwrapper default directory.

I have already looked into the documentation and so far nothing, I have seen something about suprocess Popen method I do not know if it can be applied to my example.

If I set the variable manually 'set WORKON_HOME =% cd%' on the terminal and use and use the second part of the script to initialize venv, also no error more nothing happens !!! A virtual environment already exists in the 'venv' folder.

subprocess.check_call(['workon', 'venv'], shell=True)

I have tried other subprocess.check_call and they function normally. I'm already thinking that there is no way to configure this variable and initialize venv with a python script in Windows 10?

Use: Python 3.6.5, Windows 10 Build SO 17134.285, virtualenvwrapper == 4.8.2, virtualenvwrapper-win == 1.2.5

    
asked by anonymous 22.09.2018 / 15:05

0 answers