1

I need to install numpy on a remote Raspberry Pi Zero. I know how to do it on a local machine, but my Zero has already been deployed as a surveillance camera running MotioneyeOS. I can SSH to the Zero and save programs on it, but it doesn't have apt-get or pip or numpy. It does have Python 2.7, picamera, and distutils. I don't know how to install packages without apt-get or pip on the remote computer.

Basically, all I want to do is use the pi camera to get an average reading of the ambient light. I found this python script that seems exactly what I need, but it calls numpy. Any ideas how to install numpy on a remote? I've tried figuring this out for days, unsuccessfully. Any ideas are welcome and appreciated. Here's the program I'd like to use:

import picamera
import picamera.array
import numpy as np
with picamera.PiCamera() as camera:
    camera.resolution = (100, 75)
    with picamera.array.PiRGBArray(camera) as stream:
        camera.exposure_mode = 'auto'
        camera.awb_mode = 'auto'
        camera.capture(stream, format='rgb')
        pixAverage = int(np.average(stream.array[...,1]))
print ("Light Meter pixAverage=%i" % pixAverage)
1
  • sudo apt install python{,3}-numpy should work on Stretch and Buster.
    – Dougie
    Oct 6, 2019 at 23:12

2 Answers 2

2

Making a few assumptions about how everything has been configured, you can essentially just directly extract the contents of a *.deb into the root of the file system. You should never, ever, do this on a system where apt is working properly, but if apt isn't available, here's what you do.

BUT FIRST, A WARNING!

MANUALLY INSTALLING PACKAGES AS DESCRIBED BELOW IS BAD AND YOU CAN EASILY REALLY MESS THINGS UP!

BACKUPS BEFORE HAND ARE HIGHLY RECOMMENDED!

Find out what package you need, which you can find out by running, e.g. for numpy apt-cache search numpy on a Pi with apt. Alternatively you can browse http://mirrordirector.raspbian.org/raspbian/dists/stable/main/binary-armhf/Packages, which contains a full list of packages. You can then download the *.deb file for your package from the Rasbian mirrordetect, e.g. for python-numpy http://mirrordirector.raspbian.org/raspbian/pool/main/p/python-numpy/python-numpy_1.16.5-1_armhf.deb. Extract this file using the GUI, or if no tool automatically opens it the command ar x python-numpy_1.16.5-1_armhf.deb. You should find among the files extracted a data.tar.xz file. This contains all of the contents that apt installs. You can do (roughly) what apt would do by running sudo tar -xf data.tar.xz -C /. To avoid accidentally doing something bad, you can run just tar -xf data.tar.xz which will extract the files into the current directory. You can then check to see what would be overwritten, and manually copy files as needed to avoid this.

Just installing python-numpy may not be enough to get numpy working as since this is manual you have to follow the dependency tree. This is given in the Packages file mentioned above. In the case of python-numpy,

Depends: python (<< 2.8), python (>= 2.7~), python2.7:any, python:any (<< 2.8), python:any (>= 2.7~), libblas3 | libblas.so.3, libc6 (>= 2.27), liblapack3 | liblapack.so.3, python-pkg-resources

Based on that, you'll probably also need to track down libblas3 and liblapack3 and install those manually as well, and in turn follow there dependencies. See why package managers are so great?

Note 1: Even if apt isn't available dpkg may be! You can install from the .deb file directly then using dpkg -i python-numpy_1.16.5-1_armhf.deb.

Note 2: This doesn't do any post-install configuration of packages that apt might do! You can find what it would have done in the control.tar.xz file, and manually carry out these steps.

Note 3: If you aren't running stable Raspbian, (currently Buster) then the links above will download the wrong package, check which Raspbian you're on using cat /etc/issue and edit the links swapping out 'stable', etc., as needed.

Note 4: These steps also assume you're familiar with getting files onto your remote Pi via wget or scp or some other file transfer tool (such as inserting the SD card into another PC).

1
  • Note that the OP states Python 2.7. I take it the procedure is likely the same but you might want to adapt the specifics.
    – Ghanima
    Oct 6, 2019 at 22:47
0

If you download the python-numpy_1.16.2-1_armhf.deb file (and all the dependencies) and transfer to the Pi they can be installed with:-

dpkg -i python-numpy_1.16.2-1_armhf.deb

apt is actually a front end for dpkg which automatically manages dependencies.

Depends: python (<< 2.8), python (>= 2.7~), python2.7:any, python:any (<< 2.8), python:any (>= 2.7~), libblas3 | libblas.so.3, libc6 (>= 2.27), liblapack3 | liblapack.so.3, python-pkg-resources

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.