Virtualenv, no-site-packages, sys.path
Asked Answered
G

1

9

My essential problem is that I can't get --no-site-packages to "work."

I have read a bunch of posts on SO, including this post. I'm a huge Ubuntu noob, and not much better when it comes to how python interacts with the os.

Other posts suggested that printenv would display PYTHONPATH When I am in my virtualenv, printenv doesn't appear to list "PYTHONPATH", but it's quite possible that what I should be looking for is a particular dir that I'm not aware of instead of the uppercase letters.

What I have noticed, however, is that when I run the python shell within the virtualenv, all of my global packages are listed.

I'm not sure if this is an issue with virtualenv, .bashrc, Ubuntu or my brain. Any help would be greatly appreciated.

If there's some kind, knowledgeable soul out there who is willing to help me out in a sort of back-and-forth process, I'd be very grateful. I haven't listed any of my output because, honestly, aside from the above, I'm not entirely sure where to start.

Edit in response to comments; UTC: 07:41 19 Nov 2015

Starting the environment:

notanambiturner@computer:~/Dropbox/$$ P/...$ virtualenv --no-site-packages venv
New python executable in venv/bin/python
Installing setuptools, pip, wheel...done.

Entering the environment:

notanambiturner@computer:~/Dropbox/$$ P/...$ source venv/bin/activate
(venv)notanambiturner@computer:~/Dropbox/$$ P/...$

System Packages:

(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ pip freeze
adium-theme-ubuntu==0.3.4
apt-xapian-index==0.46
beautifulsoup4==4.4.1
bleach==1.4.2
blinker==1.3
cffi==1.1.2
characteristic==14.3.0
chardet==2.3.0
colorama==0.3.3
command-not-found==0.3
....
virtualenv==13.1.2
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.1
wheel==0.26.0
whitenoise==1.0.6
xdiagnose==3.8.1
zope.interface==4.1.2
(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ 

sys.path:

(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['',
'/usr/lib/python2.7', 
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', 
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',     
'/home/notanambiturner/.local/lib/python2.7/site-packages',   
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
>>> 

You can clearly see that site-packages is included in sys.path which is super annoying.

Python3 seems slightly better, not that I know how to use pip freeze with it (or even if I can):

(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ python3
Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/usr/lib/python3.4/lib-dynload',
 '/usr/local/lib/python3.4/dist-packages',
 '/usr/lib/python3/dist-packages']
>>> 

Next edit. My mind is bottled further. UTC 08:00 19 Nov 2015

Because I'm a conspiracy theorist, I tried creating a venv outside of Dropbox.

notanambiturner@computer:~$ source venv/bin/activate
(venv)notanambiturner@computer:~$ pip freeze
wheel==0.24.0
(venv)notanambiturner@computer:~$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['',
 '/home/notanambiturner/venv/lib/python2.7',
 '/home/notanambiturner/venv/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/notanambiturner/venv/lib/python2.7/lib-tk',
 '/home/notanambiturner/venv/lib/python2.7/lib-old',
 '/home/notanambiturner/venv/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/notanambiturner/venv/local/lib/python2.7/site-packages',
 '/home/notanambiturner/venv/lib/python2.7/site-packages']
    >>> 

What... the... heck... ? I mean, I suppose that's some sort of progress? Maybe there's something to do with my filenames (\$\$\ P/) that is causing issues? From what I've read, as long as I sudo rm -rf venv it should make no difference that I have created and deleted virtualenvs in the same directory previously. Is that right?

Argh.

Gillett answered 18/11, 2015 at 18:3 Comment(8)
Can you please enter the environments, run python and run import sys; print(sys.path) inside python; then add all the inputs and outputs you did/received to your post by editing it?Victim
It is mostly related how to you activate for your virtualenv. Please post full commands and their output how you run them.Fanfaron
Thanks folks! I can't tell you how good it feels to have someone helping me with this super annoying problem. I have edited the post per your comments. Thanks for your help!Gillett
@KlausD. updated! :)Gillett
@MikkoOhtamaa updated! :}Gillett
Looks like a bug in path quoting. If you can replicate it outside Dropbox, you might report that. You can delete virtual environments safely.Victim
@KlausD. I'm not sure I understood your last comment. You're thinking it's just a bug in virtualenv?Gillett
If you didn't know, "--no-site-packages DEPRECATED. Retained only for backward compatibility. Not having access to global site-packages is now the default behavior."Trituration
G
-1

There is a bug when using $ in the path name (at least on Ubuntu).

Gillett answered 24/11, 2015 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.