title: VirtualEnv/Pip trying to install packages globally
body: <p><strong>Edit #2</strong> Solution found; see below.</p>
  
  <p>I'm writing a small application in Flask using VirtualEnv. This is far from the first time I've done this, but the this time and past two times I've tried I've encountered the same problem. When I <code>.  flask/bin/activate</code> and try to install a package -- <code>pip install flup</code>, for instance -- it keeps being installed globally, and not in the VirtualEnv. The weird thing is, it only happens after I <code>deactivate</code>, and it does so inconsistently at that.</p>
  
  <p>To wit, I seem to be able to install everything I need if I do it all at once, and even occasionally after I <code>deactivate</code>, but after a certain interval it just <em>stops working</em> and it starts trying to install into my global Python <code>site-packages</code>. (Naturally, it's also asking for permissions when it does this. Before I understood what was going on I tried to force it with <code>sudo</code>, thinking I'd brought it upon myself by accidentally <code>sudo virtualenv flask</code>-ing or something, but nope, it's going global for some other reason.)</p>
  
  <p>I'm not doing anything funny like using the <code>--system-site-packages</code> argument, and I hadn't changed anything in my VirtualEnv configuration before it started happening. The first time it happened, I chalked it up to a fluke. Now it's becoming seriously irritating because I'm not in the mood to uninstall everything and reinstall it each time, or pray that I'll think of everything I need in a bootstrap script.</p>
  
  <p>I'm not including any error messages because they aren't (or don't seem to be) particularly valuable; it's just <code>requirement already satisfied</code> yelling at me over and over.</p>
  
  <p><strong>Edit #1</strong> I'm winnowing down the problem a little bit, but I still don't have a solution. I created a new Flask project in the same directory, <code>cd</code>-ed into it, activated its VirtualEnv, etc., then ran <code>which pip</code>. It was the new VirtualEnv's pip -- the right pip. I deactivated, <code>cd</code>-ed to my original project, activated VirtualEnv, and ran <code>which pip</code>. It spit out the other project's -- the new one's -- pip. I <code>rm -r</code>-ed the new test project, went back to the original, ran <code>which pip</code> again, and it spit out <code>/usr/local/bin/pip</code>. Oh. OK.</p>
  
  <p><strong>Edit #2: Solution</strong> I may not have figured out the exact cause, but I did find the solution. The <code>bin/activate</code> and <code>bin/pip</code> scripts themselves were altered somehow, possibly from accidentally running two VirtualEnvs at the same time(?). Maybe it's just coincidence that it happened three times in a row after never happening before. Dunno.</p>
  
  <p>I <code>cat</code>-ed <code>activate</code> and sure enough, on line 42, was</p>
  
  <pre><code>VIRTUAL_ENV="/Users/chaseries/blueprint/python/flask2/flask"
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>VIRTUAL_ENV="/Users/chaseries/blueprint/python/flask/flask"
  </code></pre>
  
  <p>I changed it, ran <code>which pip</code> again, and got the right result. Tried installing, got a stack trace that led me to <code>bin/pip</code>, and found its shebang was wrong. Changed it to the right path, and everything works perfectly.</p>