title: How to fix broken python 2.7.11 after OSx updates
body: <h1>What happened:</h1>
  
  <p>After an OSx update and installing a new version of <code>python 2.7</code> my <code>virtualevn</code> environment completely broke and I struggled in fixing it. I wasn't sure what caused it and went through a whole set of things that I did and read initially that <strong>didn't work</strong> are listed below. What solved my problem is provided in the answer section.</p>
  
  <h2>What didn't work to fix <code>virtualenv</code> command not found:</h2>
  
  <ul>
  <li>Installed python through homebrew and then used pip to install virtualenv</li>
  <li>Installed python through <a href="https://www.python.org" rel="noreferrer">https://www.python.org</a> and then used pip to install virtualenv </li>
  </ul>
  
  <p>Related questions that helped me but did not provide the solution to my problem:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/31133050/virtualenv-command-not-found">virtualenv-command-not-found</a></li>
  <li><a href="https://stackoverflow.com/questions/21928555/virtualenv-workon-command-not-found">virtualenv-workon-command-not-found</a></li>
  </ol>
  
  <h2>Complete manual recovery I went through (What not to do!):</h2>
  
  <p>This didn't completely solved my problem. It is just to give you an idea of what steps I went through before I found the correct way to fix my python dev environment on my OSx. </p>
  
  <ul>
  <li>Removed python 2.7 by using the post in <a href="https://stackoverflow.com/questions/3819449/how-to-uninstall-python-2-7-on-a-mac-os-x-10-6-4">here</a></li>
  <li>Removed the homebrew installed version</li>
  <li>Installed python through the pkg file in <a href="https://www.python.org/ftp/python/2.7.10/python-2.7.10-macosx10.5.pkg" rel="noreferrer">Mac OS X 32-bit i386/PPC installer</a> or <a href="https://www.python.org/ftp/python/2.7.10/python-2.7.10-macosx10.6.pkg" rel="noreferrer">Mac OS X 64-bit/32-bit installer</a></li>
  <li><p>Manually installed virtualenv following the instructions from <a href="https://virtualenv.pypa.io/en/latest/installation.html" rel="noreferrer">here</a>:</p>
  
  <pre><code> curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-13.1.2.tar.gz
   tar xvfz virtualenv-13.1.2.tar.gz 
   cd virtualenv-13.1.2 
   sudo python setup.py install
  </code></pre></li>
  <li><p>Manaully install <code>pip</code> through <a href="https://stackoverflow.com/questions/5585875/what-is-the-official-preferred-way-to-install-pip-and-virtualenv-systemwide?lq=1">7</a>:
       curl --silent --show-error --retry 5 <a href="https://bootstrap.pypa.io/get-pip.py" rel="noreferrer">https://bootstrap.pypa.io/get-pip.py</a> | sudo python2.7</p></li>
  </ul>
  
  <h3>PIP was still broken after all this:</h3>
  
  <p>After all this after creating a virtual environment my pip still installed the packages in the main python folder instead of installing them under the virtual environment and non of the threads <a href="https://stackoverflow.com/questions/25607837/pip-install-not-installing-into-correct-directory">here</a> neither <a href="https://stackoverflow.com/questions/20952797/pip-installing-in-global-site-packages-instead-of-virtualenv">here</a> helped. My solution to that was to run pip under my virtual env with the following options:
  1- Activate the virtual environment so that <code>$VIRTUAL_ENV</code> is set:</p>
  
  <pre><code>source venv/bin/activate
  </code></pre>
  
  <p>2- Forces pip to install in the right destination:</p>
  
  <pre><code>pip install --target=$VIRTUAL_ENV/lib/python2.7/site-packages   
  </code></pre>
  
  <h2>Summary</h2>
  
  <p>Something was badly broken and best way I fix my dev environment is provided in the answer to this question. </p>