uv: Python dev headers missing in venv

I think python dev headers are now missing when uv installs venv; repro (start from ubuntu 22.04):

confirmed on uv==0.5.0 and 0.5.4, not tested on other versions

export $VIRTUAL_ENV=/tmp/.venv
curl -LsSf https://astral.sh/uv/0.5.0/install.sh | sh
. $HOME/.local/bin/env
uv venv --python 3.10 $VIRTUAL_ENV 
. $VIRTUAL_ENV/bin/activate
uv pip install ihm

output:

[stderr]
src/ihm_format_wrap_1.7.c:203:11: fatal error: Python.h: No such file or directory
  203 | # include <Python.h>
      |           ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
  Caused by: This error likely indicates that you need to install a library that provides "Python.h" for ihm@1.7

Annoyingly, it used to work - I was able to install this package, but a couple of weeks ago binaries shipped with uv were swapped for some other builds, this affected even previous versions of uv.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 27 (11 by maintainers)

Most upvoted comments

Do you think it’s worth expanding in docs when is it reasonable to attempt to use sysconfigpatcher by adding a note to python-versions.md or maybe a troubleshooting faq.

It’s sort of a priority for me to understand the problems people are encountering and fix it here rather than recommend sysconfigpatcher — it’s nice that it exists and I’m sure we’ll learn from it but I’d prefer a first-party solution.

@arogozhnikov your failing example uses the system interpreter (3.11 is installed in the image already)

root@c0d1cea75e52:/# uv python list
cpython-3.13.0+freethreaded-linux-x86_64-gnu    <download available>
cpython-3.12.7-linux-x86_64-gnu                 <download available>
cpython-3.11.10-linux-x86_64-gnu                <download available>
cpython-3.11.2-linux-x86_64-gnu                 /usr/bin/python3.11
cpython-3.11.2-linux-x86_64-gnu                 /usr/bin/python3 -> python3.11
cpython-3.11.2-linux-x86_64-gnu                 /bin/python3.11
cpython-3.11.2-linux-x86_64-gnu                 /bin/python3 -> python3.11
cpython-3.10.15-linux-x86_64-gnu                <download available>
cpython-3.9.20-linux-x86_64-gnu                 <download available>
cpython-3.8.20-linux-x86_64-gnu                 <download available>
cpython-3.7.9-linux-x86_64-gnu                  <download available>
pypy-3.10.14-linux-x86_64-gnu                   <download available>
pypy-3.9.19-linux-x86_64-gnu                    <download available>
pypy-3.8.16-linux-x86_64-gnu                    <download available>
pypy-3.7.13-linux-x86_64-gnu                    <download available>

That’s why you need to install development headers via the system package manager.

If you force uv to use a managed interpreter with --python-preference only-manage, the example works

docker run --platform linux/x86_64 -it --rm ghcr.io/astral-sh/uv:bookworm /bin/bash -c "apt update && apt install clang --yes && uv venv -p 3.11 --python-preference only-managed && uv pip install ihm"

My last example now also works as of 0.5.10 release without the need for CC=gcc 🥳

> docker run --platform linux/x86_64 -it --rm ghcr.io/astral-sh/uv:0.5.10-bookworm /bin/bash -c "uv venv -p 3.11.10 && uv pip install ihm"
Using CPython 3.11.10
Creating virtual environment at: .venv
Resolved 2 packages in 406ms
   Built ihm==1.8
Prepared 2 packages in 2.72s
Installed 2 packages in 2ms
 + ihm==1.8
 + msgpack==1.1.0

Yeah for me that’s separate from this issue (though a good point from @samypr100).

I presume the point is that we’d need #9916 for that example to work?

👋 @wjakob, the docker examples here are to provide an MRE, you can apply the same steps outside of docker.

If you’re using a system interpreter, you should install the headers, e.g., the following works:

docker run --platform linux/x86_64 -it ghcr.io/astral-sh/uv:bookworm /bin/bash -c "apt update && apt install python3-dev && uv venv && uv pip install ihm"

I can’t reproduce this failure using a managed interpreter:

docker run --platform linux/x86_64 -it ghcr.io/astral-sh/uv:bookworm /bin/bash -c "apt update && apt install clang && uv venv -p 3.10 && uv pip install ihm"