Why is my python programme running correctly in my virtual environment despite not having the packages installed in that environment?
<p>Hi all I hope I can get some help with this. I am on Windows XP, using Python 2.7.12 and command prompt.</p>

<p>I have written a programme balances.py which uses <code>prettytable</code> package. This is installed in my main <code>C:\Python27\Lib\site-packages</code> folder.</p>

<p>I just created a virtual environment:</p>

<pre><code>C:\Environments\virtualenv p1_env 
</code></pre>

<p>and activate the environment:</p>

<pre><code>C:\Environments\p1_env\Scripts\activate
</code></pre>

<p>Now I am in p1_env:</p>

<pre><code>(p1_env)C:\
</code></pre>

<p>and navigate to <code>&lt;p1_env&gt;C:\Python Projects\balances.py</code></p>

<p>and it runs the script even though I have not installed <code>prettytable</code> in <code>p1_env</code></p>

<p><code>pip list</code> for main python installation is </p>

<pre><code>virtualenv, setuptools, pip, prettytable 
</code></pre>

<p>and the <code>pip list</code> for p1_env is </p>

<pre><code>pip, setuptools, wheel
</code></pre>

<p>When i run the script balances.py in <code>p1_env</code> it still runs with <code>prettytable</code>. </p>

<p>My question is why is balances.py running in <code>p1_env</code> even though <code>prettytable</code> is not installed in <code>p1_env</code>? </p>

<p>Someone has written an answer I found : </p>

<p>odie5533 answer on <a href="http://stackoverflow.com/questions/1382925/virtualenv-no-site-packages-and-pip-still-finding-global-packages">virtualenv --no-site-packages and pip still finding global packages?</a></p>

<p><strong>A similar problem can occur on Windows if you call scripts directly as script.py which then uses the Windows default opener and opens Python outside the virtual environment. Calling it with python script.py will use Python with the virtual environment.</strong></p>

<p>So All I had to do was write "python balances.py" instead of just "balances.py". Still want it to work when I just type balances.py but nothing to get worked up over.</p>

<p>Thanks for your help everyone.</p>

python virtualenv