Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible create a virtualenv using the venv module

Tags:

How can one use Ansible to create a virtualenv using the venv module from Python3's standard library?

Manually, one would do this to create a venv (virtual environment):

python3 -m venv <venv-name> 

How do I do this using Ansible?

like image 658
Flux Avatar asked Mar 03 '17 12:03

Flux


People also ask

Is VENV the same as Virtualenv?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.


1 Answers

I ran into the same issue tonight and found that specifying the full path to the interpreter, including the arguments, worked for me (at least it does in ansible==2.2.2.0):

- pip:      requirements: /website/requirements.txt      virtualenv: /opt/website-venv      virtualenv_command: /usr/bin/python3.6 -m venv 

or

- pip:     requirements: /opt/project/requirements_prod.txt     virtualenv: /opt/.virtualenv/project_env     virtualenv_python: python3 
like image 92
joemeilinger Avatar answered Sep 18 '22 05:09

joemeilinger