First install pipenv in case you don't have it:

pip install --user pipenv

Next, for testing create a directory /tmp/my-ansible, within that directory create a file named requirements.txt with the following content:


cd in to /tmp/my-ansible or if you already have a working project cd in to it and run:

pipenv install -r requirements.txt

Or you could just run:

pipenv install ansible

It will create 2 new files Pipfile and Pipfile.lock.

To active virtualenv in the project just run:

pipenv shell

That will activate the environment for your working directory and launch/run your project based on your settings/requirements.txt.

ansible --version

When finish just type exit

In case you would like to remove the virtualenv created by pipenv run:

pipenv --rm

More info here: