Adding to @Mohit's answer,
For CentOS and RHEL:
sudo yum install python-virtualenv
For ubuntu:
sudo apt install python-virtualenv
Once you've installed you create a virtual environment
virtualenv myansible
source myansible/bin/activate
Now install ansible
pip install ansible