Inserting cli options into virtualenv.cli_run within a python file

Question:

Problem Code Picture

I want to write a Python script that creates a new virtual environment with the following virtualenv CLI options:

--app-data APP_DATA (a folder APP_DATA for the cache)

--seeder {app-data,pip}

If I give those two as strings in a list (see picture) I get:

TypeError: options must be of type VirtualEnvOptions
Asked By: SQZ11

||

Answers:

When you call cli_run as part of virtualenv, you don’t need to include the first argument, in this case "venv".

this should work:

from virtualenv import cli_run
cli_run(["--app-data APP_DATA", "--seeder {app-data,pip}"]);
Answered By: Sourabh Burse

According to virtualenv‘s documentation section "Programmatic API", this seems like the following should work:

from virtualenv import cli_run

cli_run(['path/to/venv', '--app-data', 'path/to/app_data', '--seeder', 'app-data'])
Answered By: sinoroc
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.