Install pip3 package using ansible instead of pip2


I am trying to setup a Django project in vagrant using ansible. I have used the following code for installing the pip packages:

I need to use python3 for the django project and even though I have explicitly mentioned to use python3, it is installing the pip packages via pip2. I have ensured that python3 is installed on the virtual machine.

Please, help me install the packages via pip3.


Try to use executable option. Excerpt from pip module doc:

executable (added in 1.3)

The explicit executable or a pathname to the executable to be used to run pip for a specific version of Python installed in the system. For example pip-3.3, if there are both Python 2.7 and 3.3 installations in the system and you want to run pip for the Python 3.3 installation. It cannot be specified together with the ‘virtualenv’ parameter (added in 2.1). By default, it will take the appropriate version for the python interpreter use by ansible, e.g. pip3 on python 3, and pip2 or pip on python 2.


To combine virtualenv path and alternative executable, use virtualenv_command like this:

Absolute path is required for virtualenv_command.

Leave a Reply