We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

8 posts • Page 1 of 1
Bzdurek
Posts: 10
Joined: Wed Mar 11, 2020 10:21 pm

how do you install numpy in venv?

Thu Aug 14, 2025 8:34 pm

Pi Zero W, Python 3, Bookworm

In theory it should be trivial:

Code: Select all

python3 -m venv ws
source ~/ws/bin/activate
pip install numpy
But it doesn't work. Instead of downloading ready code my pi tries to compile everything, it takes days (not sure how long actually, after 24h I had to leave for three days), and eventually it fails:

Code: Select all

 Installing backend dependencies: still running...
 Installing backend dependencies: still running...
 Installing backend dependencies: finished with status 'done'
 Preparing metadata (pyproject.toml): started
 Preparing metadata (pyproject.toml): finished with status 'done'
 Collecting ninja>=1.8.2
 Using cached https://www.piwheels.org/simple/ninja/ninja-1.11.1.4-py3-none-linux_armv6l.whl (134 kB)
 Building wheels for collected packages: patchelf
 Building wheel for patchelf (pyproject.toml): started
 Building wheel for patchelf (pyproject.toml): finished with status 'error'
 error: subprocess-exited-with-error
 ×ばつ Building wheel for patchelf (pyproject.toml) did not run successfully.
 │ exit code: 1
 ╰─> [29 lines of output]
 *** scikit-build-core 0.11.5 using CMake 4.0.3 (wheel)
 *** Configuring CMake...
 loading initial cache file build/py3-none-linux_armv6l/CMakeInit.txt
 -- The C compiler identification is GNU 12.2.0
 -- The CXX compiler identification is GNU 12.2.0
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc - skipped
 -- Detecting C compile features
 -- Detecting C compile features - done
 -- Detecting CXX compiler ABI info
 -- Detecting CXX compiler ABI info - done
 -- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++ - skipped
 -- Detecting CXX compile features
 -- Detecting CXX compile features - done
 -- Configuring done (9.5s)
 -- Generating done (0.1s)
 -- Build files have been written to: /tmp/pip-install-b61tw2r9/patchelf_441f840ce8c346368ac9be1b8c3c43a5/build/py3-none-linux_armv6l
 *** Building project with Unix Makefiles...
 [ 11%] Creating directories for 'build_patchelf'
 [ 22%] No download step for 'build_patchelf'
 [ 33%] No update step for 'build_patchelf'
 [ 44%] Performing patch step for 'build_patchelf'
 ./bootstrap.sh: 2: autoreconf: not found
 gmake[2]: *** [CMakeFiles/build_patchelf.dir/build.make:114: build_patchelf-prefix/src/build_patchelf-stamp/build_patchelf-patch] Error 127
 gmake[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/build_patchelf.dir/all] Error 2
 gmake: *** [Makefile:136: all] Error 2
 *** CMake build failed
 [end of output]
(earlier it was failing with a message about missing OpenSSL development package, but I installed the package and it gets past that step).

Installing global version of numpy with "sudo apt install python3-numpy" works nicely, but is of no use in venv.

Any ideas/suggestions?

rpdom
Posts: 25254
Joined: Sun May 06, 2012 5:17 am

Re: how do you install numpy in venv?

Thu Aug 14, 2025 8:39 pm

Bzdurek wrote:
Thu Aug 14, 2025 8:34 pm
Installing global version of numpy with "sudo apt install python3-numpy" works nicely, but is of no use in venv.
Why not? Did you create the venv with --system-site-packages ?
Unreadable squiggle

B.Goode
Posts: 18782
Joined: Mon Sep 01, 2014 4:03 pm

Re: how do you install numpy in venv?

Thu Aug 14, 2025 8:42 pm

Bzdurek wrote:
Thu Aug 14, 2025 8:34 pm

Installing global version of numpy with "sudo apt install python3-numpy" works nicely, but is of no use in venv.

Any ideas/suggestions?

It wasn't your substantive question, but why is the apt-installed version of python3-numpy of no use?

There is Raspberry Pi Documentation here - Install Python packages using apt - https://www.raspberrypi.com/documentati ... -using-apt


You may need to take account of the Tip highlighted later on -
Tip
Pass the --system-site-packages flag before the folder name to preload all of the currently installed packages in your system Python installation into the virtual environment.

{Edit: yes, same response discovered after typing it in... Left for emphasis.}
Beware of the Leopard

gordon77
Posts: 9265
Joined: Sun Aug 05, 2012 3:12 pm

Re: how do you install numpy in venv?

Thu Aug 14, 2025 8:51 pm

I don't know if it's relevant here but note this about numpy versions...

viewtopic.php?t=390865#p2331659

I believe raspios comes with numpy installed

Bzdurek
Posts: 10
Joined: Wed Mar 11, 2020 10:21 pm

Re: how do you install numpy in venv?

Fri Aug 15, 2025 7:55 pm

Thanks guys, --system-site-packages helped.

In my defense most pages I visited before asking here warned against installing packages globally and suggested to use pip only, so I didn't even try to dig deeper in that direction (and venv is not something I am familiar with). Apparently as usual good practices say one thing, and reality says screw good practices.

robertojguerra
Posts: 114
Joined: Thu Dec 05, 2024 6:35 pm

Re: how do you install numpy in venv?

Thu Nov 13, 2025 10:29 pm

Inside a venv, pip will compile numpy from source because the pip website does not host the 32 bit arm version.

You can make your own pip wheel for 32 bit numpy, back it up, and then install it in every venv you want to use it.

DirkS
Posts: 11516
Joined: Tue Jun 19, 2012 9:46 pm

Re: how do you install numpy in venv?

Thu Nov 13, 2025 11:07 pm

robertojguerra wrote:
Thu Nov 13, 2025 10:29 pm
Inside a venv, pip will compile numpy from source because the pip website does not host the 32 bit arm version.

You can make your own pip wheel for 32 bit numpy, back it up, and then install it in every venv you want to use it.
Have you tried that on a Pi02 (see OP)?

robertojguerra
Posts: 114
Joined: Thu Dec 05, 2024 6:35 pm

Re: how do you install numpy in venv?

Fri Nov 14, 2025 1:14 am

No, but I compiled opencv with non-standard options (Wayland) and installed it via pip in a venv, without contaminating the operating system, in a 64 bit arm.

I think it would help you in your 32 bit problem, if you are able to download and compile numpy, but stop before "sudo make install" and instead make a pip wheel package.

Update:
I used this guide to create my opencv wheel
https://medium.com/@sachinsoni600517/op ... b0b7d00c11

adapt the instructions to create your numpy wheel for 32 bits

8 posts • Page 1 of 1

Return to "Python"

AltStyle によって変換されたページ (->オリジナル) /