Skip to content

venv with include-system-site-packages=true not finding system modules when Python comes from Homebrew on Linux #136425

Closed as not planned
@matlo607

Description

@matlo607

Bug report

Bug description:

Issue

Script:

import sys

print(f"sys.base_prefix = {sys.base_prefix}")
print(f"sys.base_exec_prefix = {sys.base_exec_prefix}")
print(f"sys.prefix = {sys.prefix}")
print(f"sys.exec_prefix = {sys.exec_prefix}")
print(f"sys.path = {sys.path}")

import dbm.gnu

print("hello")

I created a virtual environment using Python 3.13 from homebrew using --system-site-packages.
When I run the script, Python cannot find dbm.

sys.base_prefix = /home/linuxbrew/.linuxbrew/opt/python@3.13
sys.base_exec_prefix = /home/linuxbrew/.linuxbrew/opt/python@3.13
sys.prefix = /workplace/shrinkwrap/venv3.13
sys.exec_prefix = /workplace/shrinkwrap/venv3.13
sys.path = ['/tmp', '/home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python313.zip', '/home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13', '/home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13/lib-dynload', '/workplace/shrinkwrap/venv3.13/lib/python3.13/site-packages', '/home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13/site-packages', '/home/linuxbrew/.linuxbrew/lib/python3.13/site-packages']
Traceback (most recent call last):
  File "/tmp/test.py", line 9, in <module>
    import dbm.gnu
  File "/home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13/dbm/gnu.py", line 3, in <module>
    from _gdbm import *
ModuleNotFoundError: No module named '_gdbm'

dbm is there: /home/linuxbrew/.linuxbrew/Cellar/python@3.13/3.13.5/lib/python3.13/dbm

I created another virtual environment with the Python from the system (Python 3.12) using --system-site-packages too.
This time, the script runs successfully.

sys.base_prefix = /usr
sys.base_exec_prefix = /usr
sys.prefix = /workplace/shrinkwrap/venv
sys.exec_prefix = /workplace/shrinkwrap/venv
sys.path = ['/tmp', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/workplace/shrinkwrap/venv/lib/python3.12/site-packages', '/usr/local/lib/python3.12/dist-packages', '/usr/lib/python3/dist-packages']
hello

I had a look at https://github.com/python/cpython/blob/490eea02819ad303a5042529af7507b7b1fdabdc/Lib/site.py but could not find anything obvious. The paths seem to be set as expected.

Since /home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13 is in sys.path, why can't Python find dbm in the homebrew case, but find it with the system python ?

Environment

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.2 LTS
Release:        24.04
Codename:       noble

Pyenv.cfg from env with Python 3.12:

home = /usr/bin
include-system-site-packages = true
version = 3.12.3
prompt = 'shrinkwrap'
executable = /usr/bin/python3.12
command = /usr/bin/python3.12 -m venv --system-site-packages --prompt="shrinkwrap" /workplace/shrinkwrap/venv

Pyenv.cfg from env with Python 3.13:

home = /home/linuxbrew/.linuxbrew/opt/python@3.13/bin
include-system-site-packages = true
version = 3.13.5
prompt = 'shrinkwrap'
executable = /home/linuxbrew/.linuxbrew/Cellar/python@3.13/3.13.5/bin/python3.13
command = /home/linuxbrew/.linuxbrew/opt/python@3.13/bin/python3.13 -m venv --system-site-packages --prompt="shrinkwrap" /workplace/shrinkwrap/venv3.13

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-venvRelated to the venv moduletype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy