0

Im working on logic to automate process of pyenv virtualenv creation using subprocess. Trying to run multiple pyenv shell commands at one go as below

def subprocess_cmd(command):
    
    process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
    proc_stdout = process.communicate()[0].strip()
    process.poll()
    print (proc_stdout)

def run_cmd():
    
    python_version = "3.9.6"
    dirName = "D:/python_venv" + '/' + str(python_version)
    os.makedirs(dirName, exist_ok=True)

    try:
       subprocess_cmd('pyenv install -l,pyenv install 3.9.0,pyenv local 3.9.6,python -m venv .venv')   
    except subprocess.CalledProcessError as exception:
        return None

run_cmd()

Unfortunately, its not successful. Throwing below error

:: [Info] ::  Mirror: https://www.python.org/ftp/python
pyenv-install: definition not found: -l;

See all available versions with `pyenv install --list'.

Process finished with exit code 0
Marlon Richert
  • 5,250
  • 1
  • 18
  • 27
Sai
  • 41
  • 4
  • maybe replace `pyenv install -l` with `pyenv install --list` – Josh Friedlander Jun 07 '22 at 11:35
  • Its throwing same issue. Main issue unable to execute multiple commands. – Sai Jun 08 '22 at 04:44
  • I can't repro. How are you running the Python instance from which you are attempting to run the subprocess? – tripleee Jun 08 '22 at 09:51
  • Basically trying to create a directory, in which subprocess runs the pyenv command, which has capability to install python and create python venv. Edited my question and updated with code – Sai Jun 09 '22 at 05:19

0 Answers0