X Tutup
The Wayback Machine - https://web.archive.org/web/20230329003234/https://github.com/python/cpython/issues/102733
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 returns also the venv dir #102733

Open
timendum opened this issue Mar 15, 2023 · 5 comments
Open

site.getsitepackages returns also the venv dir #102733

timendum opened this issue Mar 15, 2023 · 5 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@timendum
Copy link

timendum commented Mar 15, 2023

Bug report

On Windows, the method site.getsitepackages() returns <venv>\lib\site-packages which is expected, but also <venv>, which I think is an issue.

From the documentation, it should "Return a list containing all global site-packages directories."

I've also checked in a Linux virtualenv environment, and it returns only "site-packages" and "dist-packages" folders.

Demo

PS> python -m venv test
PS> cd .\test\
PS> .\Scripts\activate
PS> python
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
['C:\\projects\\test', 'C:\\projects\\test\\lib\\site-packages']

Expected:

['C:\\projects\\test\\lib\\site-packages']

Environment

  • Operating system and architecture:: Windows 10 / amd64
  • CPython versions tested on: 3.10.10 but also 3.10.4

Linked PRs

@timendum timendum added the type-bug An unexpected behavior, bug, or error label Mar 15, 2023
@rprater
Copy link
Contributor

rprater commented Mar 15, 2023

I'll do a bit of digging on this.

@ericvsmith
Copy link
Member

Is it adding the current directory, or is it always <venv>? Try cd'ing somewhere else and see what it prints.

@timendum
Copy link
Author

@ericvsmith It's always <venv>

PS> cd c:\projects
PS> .\test\Scripts\python
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
['C:\\projects\\test', 'C:\\projects\\test\\lib\\site-packages']
>>> import os
>>> os.getcwd()
'C:\\projects'

The same also from other folders, outside c:\projects.

@rprater
Copy link
Contributor

rprater commented Mar 16, 2023

There seems to be a non site-packages directory returned from the getsitepackages() function on Windows when you are in a venv and when you are not. So I think this is less of a venv issue and more of a Windows issue.

No Virtual Environment

>>> import site
>>> site.getsitepackages()
['C:\\Program Files\\Python38', 'C:\\Program Files\\Python38\\lib\\site-packages']

Virtual Environment

>>> import site
>>> site.getsitepackages()
['C:\\Users\...\Open Source\\cpython\\venv`, 'C:\\Users\...\Open Source\\cpython\\venv\\lib\\site-packages']

Environment

  • Windows 10 / amd64
  • Python 3.8.10

@rprater
Copy link
Contributor

rprater commented Mar 25, 2023

@timendum and @ericvsmith, I believe my PR fixes the issue. I think it was just some legacy code added 14 years ago that needed to be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants
X Tutup