Skip to content

site.py not compatible with python 2.7 #355

Open
leoliu opened this Issue Nov 9, 2012 · 11 comments

9 participants

@leoliu
leoliu commented Nov 9, 2012

We use python 2.7 exclusively and it is a surprise to discover today that site.py in all virtual envs with python 2.7 use py2.6's site.py which lacks many new functions added in python 2.7.

@qwcode
Python Packaging Authority member
qwcode commented Nov 9, 2012

can you give an example of what is not working for you?

@leoliu
leoliu commented Nov 10, 2012

site.getsitepackages() doesn't work.

@pnasrat
Python Packaging Authority member
pnasrat commented Nov 10, 2012

Reproduced on OS X:

$ virtualenv -p python2.7 ve
$ ./ve/bin/python -c 'import site; print(getattr(site, "getsitepackages"))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'

Running outside venv works for me -

$ python -c 'import site; print(getattr(site, "getsitepackages"))'
<function getsitepackages at 0x104198410>``` 

$ ./ve/bin/python -c 'import site; print(site.file)'
/private/tmp/ve/lib/python2.7/site.pyc
$ python -c 'import site; print(site.file)'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc


We ship our own `./virtualenv_embedded/site.py`
@pnasrat
Python Packaging Authority member
pnasrat commented Jan 5, 2013

Consider updating (and ensuring backwardly compat) site.py

@qwcode
Python Packaging Authority member
qwcode commented Jan 24, 2013

I don't think this should be marked as a release blocker. although it would be great to support feature-compatible site.py files, this shortcoming has been like this for years.

@vhermecz

" this shortcoming has been like this for years". And hell yeah, it still hurts... :(
Consider fixing this plz, thx

@staticfloat

This bit me today; it would be really, really nice to get an updated site.py included in virtualenv since the old 2.6 version doesn't have things like site.getusersitepackages().

@RemiCardona

It bit me too, and it caught me off guard. Now I'm even wondering what other files differ from the system python (especially when using --system-site-packages) and what other "bugs" lie in wait…

@mtholder mtholder added a commit to jeetsukumaran/DendroPy that referenced this issue Jun 5, 2015
@mtholder mtholder Suppressing missing site-packages info for venv
Running via virtualenv requires a workaround for
  pypa/virtualenv#355

Here, I just omit issuing info about the site-packages
dir if the call to getsitepackages() fails.
554cc09
@mtholder mtholder referenced this issue in jeetsukumaran/DendroPy Jun 5, 2015
Merged

Suppressing missing site-packages info for venv #17

@stefano-m

Still valid using virtualenv 13.1.2 with Python 2.7.6, and it's getting in the way of some dev work I'm doing.

Here's some interactive fiddling:

getsitepackages is not present in virtualenv
$ virtualenv --version
13.1.2
$ virtualenv test
New python executable in test/bin/python
Installing setuptools, pip, wheel...done.
$ source test/bin/activate
$ which python
/home/user/test/bin/python
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> 'getsitepackages' in dir(site)
False
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'
>>>
getsitepackages is present in system Python
$ deactivate
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> 'getsitepackages' in dir(site)
True
>>> site.getsitepackages()
['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
>>>
@CptSpaceToaster

Edit: woah...... I just read: #697

I think time is probably better spent addressing root-causes, rather than this specific symptom. Depending on how the rewrite goes, I'm more than willing to wait on any changes that need to occur to solve this issue, in favor of the changes discussed in the rewrite.

Original Comment:
I just got bitten by this one as well.

# Tried with and without --system-site-packages

[username@hostname] ~/dir $ virtualenv --system-site-packages venv
Using base prefix '/usr'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Installing setuptools, pip, wheel...done.
[username@hostname] ~/dir $ venv/bin/python
Python 3.4.3 (default, Jul 28 2015, 18:20:59) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'
>>> 

please consider updating site.py to provide site.getsitepackages()

@johnthagen

Hit this issue with #555, which can cause different behaviour in a virtual environment if you run with -Werror because of the deprecation warning. Since tox depends on this package to work internally, don't see much of a way around it.

@kernc kernc added a commit to kernc/orange3 that referenced this issue May 27, 2016
@kernc kernc Fix Qt plugin paths (Refs: 59faf29)
site.getsitepackages() doesn't work inside virtualenv:
pypa/virtualenv#228
pypa/virtualenv#355
932ece8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.