Create a virtualenv from inside a python script

python, virtualenv

Solution

You can use `os` to pass commands to terminal/cmd.

import os

os.system('<command goes here>')

You can use that for any commands you'd normally run in terminal. So for a virtualenv you would just do:

import os

os.system('virtualenv nameofvirtualenv')

Problem

i'm working on a simple script in python that creates the folder structure and basic files for a new Flask project, something similar to "django-admin startproject" what i would like to do at the same time is to create a virtual environment with virtualenv from inside my script. i thought that maybe one way could be: ``` import virtualenv virtualenv.main() ``` the problem is that i can't pass arguments to the main, so this doesn't seem to work. any suggestion?

Original source