Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

site.getsitepackages() missing #737

Closed
wichert opened this issue Mar 22, 2015 · 18 comments
Closed

site.getsitepackages() missing #737

wichert opened this issue Mar 22, 2015 · 18 comments

Comments

@wichert
Copy link

wichert commented Mar 22, 2015

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'
@omeinusch
Copy link

Do you use Python 2.7? In this case, its a duplicate of #355 .

@wichert
Copy link
Author

wichert commented Apr 30, 2015

This was indeed using Python 2.7.

@zed
Copy link

zed commented Jul 30, 2017

site.getsitepackages() works on Python 2.7 and 3.2+ outside a virtualenv and I get the AttributeError inside a virtualenv on both Python 2 and 3 on Ubuntu.

As a workaround: python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" manages to find the location of my Python site-packages directory

@piotr-dobrogost
Copy link

It would be nice if any of virtualenv's maintainers took a look at this and provide some guidance as to where the problem is…

@pfmoore
Copy link
Member

pfmoore commented Jul 31, 2017

The problem (as I understand it) is that virtualenv implements its own version of site.py that doesn't track the core Python version perfectly (that's the issue behind #355, referenced above - if you follow that link, and the link to the various issues linked from there, you'll get the background).

Fixing this isn't as simple as "sync up to the core site.py", because we need to support multiple Python versions, and site.py has changed between them.

Hope that helps - I'm replying as a virtualenv maintainer offering some guidance, but it's not something I'm planning on working on myself. As usual, patches welcome, but anyone willing to take this on should be clear on the amount of testing effort involved. For example, technically I believe we still support Python 2.6, so do we need to make sure that site.getsitepackages() is unavailable on that version? (IMO, no, we should just drop support for 2.6, but I wish it were that simple 😄)

@stale
Copy link

stale bot commented Jan 14, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions.

@maludwig
Copy link

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.

@fabiencelier
Copy link

fabiencelier commented Nov 12, 2019

Same problem with Windows 10 and Python 3.7
Seems to be caused by pywin32==226

@fwalid08
Copy link

fwalid08 commented 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.

It work!s

@yue327
Copy link

yue327 commented Nov 13, 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.

Dude this is so cool!
you made my day!

@mikemcowie
Copy link

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.

@maludwig - Nice.

I'm assuming the reason virtualenv's site.py doesn't include this function is because virtualenv is supposed to keep you deliberately away from using system-wide packages? But if some package explicitly calls this function then it's inevitably going to break when trying to run in a virtualenv?

@voidspace
Copy link

I'm seeing this on multiple machines, Windows 10 Python 3.7 and 3.8. It makes virtualenv unusable unfortunately.

@okainov
Copy link

okainov commented Sep 30, 2020

Why is this one closed? Seems still reproducible also with Python 3

@gaborbernat
Copy link
Contributor

Can you post a reproducible with latest virtualenv?

@gruszczy
Copy link

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

@gruszczy
Copy link

Reported also on pyre tracker: facebook/pyre-check#326

@gaborbernat
Copy link
Contributor

Can you post a reproducible with latest virtualenv?

@gaborbernat
Copy link
Contributor

I want to know specifics, how you created the virtualenv, what was the output of the creation (with -vvv?), what host Python you're using?

NaleRaphael added a commit to NaleRaphael/codememo that referenced this issue Oct 27, 2020
Method `site.getsitepackages()` won't work with `virtualenv`, so that
we have to use `distutils.sysconfig`get_python_lib()` instead. See
also: pypa/virtualenv#737
@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests