a.costa
a.costa

Reputation: 1059

Create a virtualenv from inside a python script

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?

Upvotes: 4

Views: 937

Answers (1)

Daniel
Daniel

Reputation: 3454

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')

Upvotes: 5

Related Questions