Virtualenv: 'site' has no attribute "getsitepackages"

Created on 24 Feb 2012  ·  4Comments  ·  Source: pypa/virtualenv

Any virtualenv, with or without --system-site-packages, gives me:

% python -c 'import site; site.getsitepackages()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'

Most helpful comment

Yes, one of the uglier aspects of virtualenv's implementation is that it has to have its own copy of the site module, which is used for all virtualenvs regardless of which version of Python they are created with. And this copy predates the addition of site.getsitepackages() (first added in Python 2.7, I believe).

I would have no objection to a pull request adding that function to virtualenv's site module, as long as the implementation is one that can work on all virtualenv-supported versions of Python (2.4 through 3.3a). Or if that's too difficult due to missing APIs in other areas of the earlier Python versions, perhaps have it conditionally defined depending on sys.version or something.

All 4 comments

Yes, one of the uglier aspects of virtualenv's implementation is that it has to have its own copy of the site module, which is used for all virtualenvs regardless of which version of Python they are created with. And this copy predates the addition of site.getsitepackages() (first added in Python 2.7, I believe).

I would have no objection to a pull request adding that function to virtualenv's site module, as long as the implementation is one that can work on all virtualenv-supported versions of Python (2.4 through 3.3a). Or if that's too difficult due to missing APIs in other areas of the earlier Python versions, perhaps have it conditionally defined depending on sys.version or something.

duplicate #355

closing as dupe to #355, since it's more generic.

have this issue with Python 3.6.5

>> python --version && python -c "import site; print(site.getsitepackages())"
Python 3.6.5
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'site' has no attribute 'getsitepackages'

not duplicate of #355

Was this page helpful?
0 / 5 - 0 ratings