r/learnpython • • 2d ago

numpy build fails using uv and homebrew

I am running macOS 27.2 with homebrew and uv. Python 3.15. numpy is a requirement for the project. When uv tries to build numpy 2.5.1, it fails complaining about not finding "atomic.h", "ostream.h" and "cstddef.h".

I know this is some kind of setup problem with the c++ compiler, but can't figure it out. I have installed Xcode command line tools and pkgconf.

Any suggestions?

4 Upvotes

8 comments sorted by

7

u/Gshuri 2d ago

Is there a reason you need numpy==2.5.1?

That version of numpy was released before Python 3.15 was released, hence there are no numpy wheels built for Python 3.15, which leads to the attempt to build the package from source.

Can you use a later version of numpy? From numpy>=2.5.2 onwards there are pre-built wheels for Python 3.15 (including macOS on both intel and apple silicon).

You said your are using uv so you can try uv add "numpy>=2.5.2"

2

u/seanv507 2d ago

to add to this comment. compiling numpy (or other c++ libraries) from scratch is an 'antipattern'. Don't ever do it, unless explicitly told to in the installation!

So either do as u/Gshuri suggested or run an older version of python consistent with that numpy version (and any other outdated package versions you might run into after solving the numpy issue!). UV is very capable of installing a different python version for that project - it just defaults to the latest.

you might also use claude etc to help updating

1

u/tthkbw 2d ago

Thanks for the input. I have let uv handle this stuff since this project is currently only for my personal use.

As far as Claude goes--I currently don't use AI except to answer very simple questions that I used to look up via DuckDuckGo. I have tried it over the last three years or so for autocomplete in nvim, and also prompting for specific implementations of some functionality. But I have nearly completely stopped using AI for coding. I don't learn anything when I use AI and I feel little satisfaction in doing so even if the result is solving a problem.

However, I understand others' use of it as an efficient tool. But I am 77 and have been retired from chip design and FPGA design days for over 10 years and no one but me evaluates my productivity. Writing code keeps my mind active, is fun and challenging, and allows me to stave off dementia for a little longer.

2

u/seanv507 2d ago

I totally understand where you are coming from. However, no one forces you to use claude for vibe coding. I am suggesting you use it for unblocking you. In particular, ask it to do the grunt work of setting up a python environment, so that you can focus on programming.

Claude is pretty good at best practices. In this case, uv defaults to use whatever python you have on your machine. Claude, xan be expected to identify the strategies to unblock you. It has access to your code, so it can identify alternative ways to fix your issue. Eg as I mentioned, you have two options: downgrade python or upgrade numpy.. Depending on what other packages you import, one may be better than the other. People dont typically provide the full context to their questions, so claude can help as a 'pair programmer' looking over your shoulder, rather than a snarky stack overflow expert that assumes you have an xy problem.

1

u/tthkbw 2d ago

Putting "numpy>=2.5.2" in the pyproject.toml file fixed this! Thank you!

I was building on a new machine and wasn't surprised that uv was building some stuff in the background, but didn't think of the version of numpy as a problem. numpy is required by one of the libraries I use, not by my code directly.

Anyway, I learned something, and now it all works.

1

u/jmacey 2d ago

There is really no need to use python 3.15 at the moment. There are a lot of libraries that don't work well (pytorch etc).

I can get it working on my mac (uv intalled via homebrew)

uv init -p 3.15 testnumpy
cd testnumpy
uv add numpy
Using CPython 3.15.2
Creating virtual environment at: .venv
Resolved 2 packages in 104ms
      Built testnumpy @ file:///Users/jmacey/tmp/testnumpy                                                                Prepared 1 packages in 381ms
Installed 1 packages in 852ms
 + numpy==2.5.4
uv run python -c "import numpy as np; print(np.__version__)"
2.5.4

So it is working, but I'm sure there are a lot of edge cases that don't as yet.

1

u/tthkbw 2d ago

I had just ported this project to 3.15 to take advantage of the lazy imports because I wanted to optimize startup time. I chose the 3.15 dependency for my own reasons.

3

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 2d ago

I had just ported this project to 3.15 to take advantage of the lazy imports because I wanted to optimize startup time.

Frankly, lazy imports don't have a major impact on startup time outside of exceptional cases (mostly if importing a huge package, but the execution path only needs it under specific circumstances, and usually doesn't).

I haven't heard much discussion on this yet, but personally I think they're most convenient for things like type annotations and for resolving certain cases where import order is significant (one specific example I've run into at work is the ftd2xx library, where I think something needed to be imported and initialised before importing that, probably some kind of models).

3.14 is still perfectly fine to use. I'd personally default to that unless all of your dependencies already support 3.15. In your project, they seemingly do, in some others that may not be the case.