astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
21.74k stars 636 forks source link

`dbm.gnu` not available #7197

Open suomela opened 3 weeks ago

suomela commented 3 weeks ago

My system Python defaults to using dbm.gnu when I use the dbm module (macOS, Homebrew, installed python@3.12 and python-gdbm@3.12.

However, Python from uv apparently does not provide dbm.gnu, and hence cannot open files created with my system Python.

Steps to reproduce:

brew install python python-gdbm
uv init --python-preference=only-managed foo
cd foo
python3 -c 'import dbm; dbm.open("test", "c")'
python3 -c 'import dbm; dbm.open("test", "r")'
uv run python -c 'import dbm; dbm.open("test", "r")'

The final command fails with:

Using Python 3.12.5
Creating virtualenv at: .venv
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/.../.local/share/uv/python/cpython-3.12.5-macos-x86_64-none/lib/python3.12/dbm/__init__.py", line 91, in open
    raise error[0]("db type is {0}, but the module is not "
dbm.error: db type is dbm.gnu, but the module is not available

It is not clear to me how do I tell uv that I would like to get a Python that supports dbm.gnu.

apollo13 commented 3 weeks ago

Probably related to this: https://gregoryszorc.com/docs/python-build-standalone/main/technotes.html?highlight=dbm#dbm -- if yes there isn't much uv can do. You can either build your own managed python (not sure if you can use that with uv though) or use the system python.