2

Hi all I hope I can get some help with this. I am on Windows XP, using Python 2.7.12 and command prompt.

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

I just created a virtual environment:

C:\Environments\virtualenv p1_env 

and activate the environment:

C:\Environments\p1_env\Scripts\activate

Now I am in p1_env:

(p1_env)C:\

and navigate to <p1_env>C:\Python Projects\balances.py

and it runs the script even though I have not installed prettytable in p1_env

pip list for main python installation is

virtualenv, setuptools, pip, prettytable 

and the pip list for p1_env is

pip, setuptools, wheel

When i run the script balances.py in p1_env it still runs with prettytable.

My question is why is balances.py running in p1_env even though prettytable is not installed in p1_env?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    Have you considered that the packages from the main python installation are transitively included in virtualenv? – OneCricketeer Sep 05 '16 at 16:55
  • I have checked both pip lists and prettytable is not in p1_env but is included in the main installation. I don't think Im following what you mean though. Thanks for responding. – Alex Muncheon Sep 05 '16 at 17:05
  • Please consider to write a better subject for this question. It should be an actual question. – jgomo3 Sep 05 '16 at 17:36
  • @jgomo3 Question is pretty clear at the bottom – Alex Muncheon Sep 05 '16 at 18:00
  • @AlexMuncheon The title should be a question, not a topic. For topics there are tags. – jgomo3 Sep 05 '16 at 22:14
  • @cricket_007 Ok I checked another thread out and it seems it might have to do with the PYTHONPATH, which i dont have set in system >> environmental variables but I do have a PATH variable set to to C:\Python27\;C:\Python27\Scripts;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem. Ermm... maybe it something to do with this I'm not sure but Ive read its best not to mess with these environmental variables so I'm hesistant to change anything here. – Alex Muncheon Sep 06 '16 at 15:37
  • Yeah, I found the same post that you did. I'm not using a Windows machine, so I can't test anything, but you are welcome to define `PYTHONPATH` to `C:\Python27\;C:\Python27\Scripts`, then update the `PATH` variable to include `%PYTHONPATH%` – OneCricketeer Sep 06 '16 at 16:44

2 Answers2

0

You have installed prettytables globally. When you create a virtual environment it will include the globally installed packages hence the reason why your program is running.

0

Someone has written an answer I found :

odie5533 answer on virtualenv --no-site-packages and pip still finding global packages?

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.

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.

Thanks for your help everyone.

Community
  • 1
  • 1