# pip tries to install to /usr/local/ not to my virtualenv

**URL:** <https://forum.ansible.com/t/pip-tries-to-install-to-usr-local-not-to-my-virtualenv/17124>\
**Category:** Ansible Project\
**Created:** [December 21, 2014, 8:50pm UTC](https://forum.ansible.com/t/pip-tries-to-install-to-usr-local-not-to-my-virtualenv/17124 "2014-12-21T20:50:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy\_Smith](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Roy\_Smith](https://forum.ansible.com/u/Roy_Smith)\
**Post date:** [December 21, 2014, 8:50pm UTC](https://forum.ansible.com/t/pip-tries-to-install-to-usr-local-not-to-my-virtualenv/17124/1 "2014-12-21T20:50:47Z")

</div>

Local setup:  
ansible 1.8.2  
python 2.7.1

Remote:  
ansible 1.8.2  
python 2.7.6  
pip 1.5.4

Playbook:

---

<div class="post-metadata">

**Author:** ![Roy\_Smith](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Roy\_Smith](https://forum.ansible.com/u/Roy_Smith)\
**Post date:** [December 21, 2014, 9:09pm UTC](https://forum.ansible.com/t/pip-tries-to-install-to-usr-local-not-to-my-virtualenv/17124/2 "2014-12-21T21:09:30Z")

</div>

Hmmm, upon further investigation, I found a Stack Overflow thread ([http://stackoverflow.com/questions/20040141/ansible-command-from-inside-virtualenv](http://stackoverflow.com/questions/20040141/ansible-command-from-inside-virtualenv)) which discussed this issue, and put me on the right path. I ended up with:

tasks:

- name: create virtualenv  
pip: chdir=“{{ remote\_base\_dir }}/deploy”  
virtualenv=python-env  
executable=“{{ remote\_base\_dir }}/deploy/python-env/bin/pip”  
requirements=pip-requirements

which seems to do the right thing. It does seem kind of counter-intuitive, however, that if you’re specifying the virtualenv to install into, it doesn’t, well, install into that. Along the way to this solution, I tried the approach of two distinct pip plays, one to create the basic virtualenv, and the other to populate it with modules. But this does the right thing in one play.
