virtualenv: site.getsitepackages() missing

The standard site.getsitepackages() function is not available in a virtualenv:

>>> import site
>>> site.getsitepackages()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getsitepackages'

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve gotten this issue on Python 3.7.0, Windows 10, in a virtualenv.

As a workaround that seems to be holding, outside of the virtualenv, I did:

python

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
['C:\\Users\\maludwig\\AppData\\Local\\Programs\\Python\\Python37', 'C:\\Users\\maludwig\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']

Then I simply edited the site.py in my virtualenv, and added the missing function:


def getsitepackages():
    return ['C:\\Users\\maludwig\\AppData\\Local\\Programs\\Python\\Python37', 'C:\\Users\\maludwig\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']

It’s a hacky workaround, but hopefully this helps someone else.

I am seeing this on Mac, with virtualenv==20.0.34 and when trying to use pyre 0.0.56.