4

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?

3
  • why not just use the 'os' library? Commented Oct 31, 2016 at 17:30
  • Try using import os and then os.system('virtualenv venv')? Commented Oct 31, 2016 at 17:31
  • doesn't the os solution have portability issues? isn't there a solution that works without invoking the os? Commented Nov 15, 2016 at 16:15

1 Answer 1

5

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')
Sign up to request clarification or add additional context in comments.

1 Comment

I don't see any portability issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.