Python can't find packages in Virtual Environment
<p>I'm trying to setup my environment for a project but python isn't able to find the modules I've installed with pip.</p>

<p>I did the following:</p>

<pre><code>mkdir helloTwitter
cd helloTwitter
virtualenv myenv
Installing setuptools, pip, wheel...done.
source myenv/bin/activate

pip install tweepy
Collecting tweepy
  Using cached tweepy-3.5.0-py2.py3-none-any.whl
Collecting six&gt;=1.7.3 (from tweepy)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting requests&gt;=2.4.3 (from tweepy)
  Using cached requests-2.11.1-py2.py3-none-any.whl
Collecting requests-oauthlib&gt;=0.4.1 (from tweepy)
  Using cached requests_oauthlib-0.6.2-py2.py3-none-any.whl
Collecting oauthlib&gt;=0.6.2 (from requests-oauthlib&gt;=0.4.1-&gt;tweepy)
Installing collected packages: six, requests, oauthlib, requests-oauthlib, tweepy
Successfully installed oauthlib-2.0.0 requests-2.11.1 requests-oauthlib-0.6.2 six-1.10.0 tweepy-3.5.0
</code></pre>

<p>When I try to import the module it says it cannot be found.</p>

<p>The first entry in $PATH is <code>helloTwitter/myenv/bin</code>
All the packages are showing up in the environments site-packages directory.
I seem to be using the right python and pip.
Which python outputs <code>helloTwitter/myenv/bin/python</code>
Which pip outputs <code>helloTwitter/myenv/bin/pip</code></p>

<p>Any advice on where I'm going wrong?</p>

<p>It looks like you're manually setting your <code>$PATH</code> to point to your virtual environment. The whole point of the <code>myenv/bin/activate</code> script is to take care of this for you. </p>

<p>Once you have activated your virtual environment, any package you install using pip will be placed in the relevant venv <code>site-packages</code> directory (in your case, <code>myenv/lib/python2.7/site-packages</code>). Things like <code>pip --user</code> are unnecessary when you are working in a virtual environment (assuming default behaviour). It's all automatic.</p>

<p>After running <code>activate</code>, you can check the python binary you are using with <code>find -iname tweepy</code>. </p>

<p>Aliases can cause issues too. <code>which</code> is an external command, and won't always pick these up. A <code>type -a python</code> will flush these out.</p>

<p>A quick test can be done by running <code>helloTwitter/myenv/bin/python -c 'import tweepy'</code> directly. If this behaves differently to however you are currently running python (i.e. doesn't throw an import exception), then this is your problem.</p>

<p>Hope that helps.</p>

python virtualenv