question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: module 'site' has no attribute 'getsitepackages'

See original GitHub issue

Issue description

python version 3.7.3 pipenv version 2018.11.26

When I try to use site.py#getsitepackages() in pipenv environment, the below error occurrs.

AttributeError: module 'site' has no attribute 'getsitepackages'

When I use the same module in pip environment, the error does not occur.

The cause is probably that pipenv doesn’t refer site.py installed in python environment. I checked the installed directory.

pipenv --venv
$HOME/.local/share/virtualenvs/$hash
ls -l $HOME/.local/share/virtualenvs/$hash/lib/python3.7 | grep site.py
-rw-rw-r--   1 $user $user 28389 Jun  6 07:13 site.py

The aforementioned site.py does not have getsitepackages() method.

The other modules refer to the modules installed in python environment.

E.g. os.py

ls -l $HOME/.local/share/virtualenvs/$hash/lib/python3.7 | grep os.py
lrwxrwxrwx   1 $user $user    51 Jun  6 07:13 os.py -> /usr/local/pyenv/versions/3.7.3/lib/python3.7/os.py

Expected result

Even in pipenv environment, site.py#getsitepackages() method is available.

Steps to replicate

Install python3.7.3 Install pipenv by pip Run the below pipenv run python -c "import site; site.getsitepackages()"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
maludwigcommented, Nov 12, 2019

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.

8reactions
vashekcommented, Nov 11, 2019

This started happening today. I installed a package in pipenv and started throwing this error. I then deleted the environment and created a new, now it won’t work. I can’t even open python.exe

Delete the virtual environment, change the pywin32 environment in your Pipfile to “==225”, and then run pipenv update. If you don’t have a pywin32 requirement, it’s probably required by another required package. Just add pywin32 with the “==225” version into your Pipfile.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - module 'site' has no attribute 'getusersitepackages'
Try running site.USER_SITE(). if you get an answer, it might mean that the site package is of an older version since the docs...
Read more >
Package fails to install in virtual env, can't find anything in the ...
getsitepackages(): AttributeError: module 'site' has no attribute 'getsitepackages' ---------------------------------------- ERROR: Command ...
Read more >
Chilkat2 Python Module for Linux Install Instructions
AttributeError: module 'site' has no attribute 'getsitepackages'. This can happen in a virtualenv because site.py does not have getusersitepackages().
Read more >
pip install arcgis - Esri Community
... in <module> File "/tmp/pip-install-o_gaembh/arcgis/setup.py", ... AttributeError: module 'site' has no attribute 'getsitepackages'
Read more >
site — Site-specific configuration hook — Python 3.11.1 ...
In that case, this module can be safely imported with no automatic modifications to the module search path or additions to the builtins....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found