Author Topic: Raspberry Pi and Python  (Read 3296 times)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Raspberry Pi and Python
« on: October 24, 2023, 23:25:59 »
I recently picked up a book called Raspberry Pi 3 Cookbook for Python Programmers, so here we go.  ;D

Out come the Raspberry Pi hardware again. It's been sitting on the shelf for much too long.

I couldn't remember sure which versions of the hardware that I have. Fortunately I found a handy reference: https://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/

I also discovered that https://www.raspberrypi.com/software/ has a Raspberry Pi Imager program that can be run on Windows, Linux, or Mac, to make it even easier than before to setup the Raspberry Pi OS onto an SD card than it was last time I had tried it.
« Last Edit: October 25, 2023, 22:53:03 by Dragon »
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Re: Raspberry Pi and Python
« Reply #1 on: October 25, 2023, 19:57:06 »
On my quest, I've discovered that I have Raspberry Pi B+ with 512 MB RAM, which unfortunately doesn't have Wi-Fi built in. I do have an old Ativa Wireless USB Network Adapter, but it wasn't just plug-and-play.

I found a list of tested Wi-Fi Adapters, https://elinux.org/RPi_USB_Wi-Fi_Adapters, but the Ativa AWGUA54 was not on the list.

A quick Google search and I've come across this: 
Quote from: https://forums.raspberrypi.com/viewtopic.php?t=95539
...you can use USB adapters if they have Raspberry PI (Linux for ARM6) drivers.

And on another site:
Quote from: http://en.techinfodepot.shoutwiki.com/wiki/Ativa_Wireless_G_USB_Adapter_(AWGUA54)
This adapter is the same as the Belkin F5D7050 v4.

Back to the first list, the entry for the Belkin says "install firmware-ralink and add usbcore to /etc/modules; use guide" and links to another site. A blogger explained the process of installing the drivers for the Raspberry Pi on Raspberry Pi Wireless - Belkin 802.11g usb adapter Ralink RT2750W.

« Last Edit: October 25, 2023, 23:04:24 by Dragon »
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Re: Raspberry Pi and Python
« Reply #2 on: October 25, 2023, 22:49:50 »
I saw on the previously mentioned website that the drivers were available at http://ftp.uk.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-ralink_0.28+squeeze1_all.deb, unfortunately, the file doesn't exist there anymore. However, I did take a look in
http://ftp.uk.debian.org/debian/pool/non-free/f/firmware-nonfree/ and found a more recent Ralink file: firmware-ralink_20190114-2_all.deb. Also, https://archive.debian.org/debian-archive/debian/pool/non-free/f/firmware-nonfree/ does have the firmware-ralink_0.28+squeeze1_all.deb and 5 others that appear to be in between those.   
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Re: Raspberry Pi and Python
« Reply #3 on: November 01, 2023, 18:05:27 »
Looks like the Ralink firmware isn't the right thing for this hardware. Running a different command, lsusb, I see [Zydas ZD12118] at the end of the line for the Belkin Components, so I'm going to try installing the zd1211 firmware, which is actually the same one mentioned on page 56 in the book I got.

Code: [Select]
sudo apt-get install firmware-zd1211
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Re: Raspberry Pi and Python
« Reply #4 on: November 15, 2023, 20:54:39 »
As a follow up to my previous comment, the USB adapter for Wi-Fi is working now.

Continuing into the 2nd chapter of Raspberry Pi 3 Cookbook for Python Programmers, I've found that I needed to install scikit-learn to have the necessary datasets. While trying to install scikit-learn on my RPI the other day, which was taking a very long time, the system went to sleep. The screen would go black after about 10 minutes and I was thinking it might be helpful to adjust the power settings so it wouldn't do that. The GUI doesn't have anything that I could find to change it, but I did find some command line stuff that worked without installing anything more.

Quote from: https://stackoverflow.com/questions/30985964/how-to-disable-sleeping-on-raspberry-pi#58698636
I found there are two settings that have to be changed as either one of them will blank the screen in ten minutes under the default settings.
set screen saver timeout to zero:

xset s 0

and set dpms (EnergyStar) to disabled:

xset -dpms

This way I haven't needed to install anything (no screensaver). It was confusing because I'd tried both items, but it wasn't until I learned they both were blanking the screen at ten minutes that I saw what was going on.
As this has tested out OK, the next step for me is to put them into an autostart routine.
ps Verify your settings with

xset q
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Re: Raspberry Pi and Python
« Reply #5 on: November 17, 2023, 23:29:21 »
Still having trouble getting scikit-learn installed, I noticed by running top that the system was running out of memory while trying to get the dependencies installed. I suspected that running straight from the command console instead of using the GUI desktop might help. I used sudo raspi-config to change the boot config and rebooted to the console. After that, I ran the install commands individually for the dependencies before trying to install scikit.

Code: [Select]
pip3 install -U numpy
pip3 install -U joblib
pip3 install -U threadpoolctl
pip3 install -U scipy
pip3 install -U scikit-learn

Finally... it all installed successfully... supposedly. To test, according to https://pypi.org/project/scikit-learn/, I also installed pytest, pip3 install -U pytest. Unfortunately, running pytest sklearn still failed.

https://scikit-learn.org/stable/install.html has more installation and troubleshooting steps that I'll need to go through.

« Last Edit: November 19, 2023, 12:16:12 by Dragon »
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Re: Raspberry Pi and Python
« Reply #6 on: December 01, 2023, 19:47:17 »
From https://scikit-learn.org/stable/install.html:

Scikit-learn plotting capabilities (i.e., functions start with “plot_” and classes end with “Display”) require Matplotlib. The examples require Matplotlib and some examples require scikit-image, pandas, or seaborn. The minimum version of Scikit-learn dependencies are listed below along with its purpose.

DependencyMinimum Version    Purpose
numpy 1.17.3 build, install
scipy 1.5.0 build, install
joblib 1.1.1 install
threadpoolctl 2.0.0 install
cython 0.29.33 build
matplotlib 3.1.3 benchmark, docs, examples, tests
scikit-image 0.16.2 docs, examples, tests
pandas 1.0.5 benchmark, docs, examples, tests
seaborn 0.9.0 docs, examples
memory_profiler0.57.0benchmark, docs
pytest 7.1.2 tests
pytest-cov 2.9.0 tests
ruff 0.0.272 tests
black 23.3.0 tests
mypy 1.3 tests
pyamg 4.0.0 tests
sphinx 6.0.0 docs
sphinx-copybutton 0.5.2 docs
sphinx-gallery 0.10.1 docs
numpydoc 1.2.0 docs, tests
Pillow 7.1.2 docs
pooch 1.6.0 docs, examples, tests
sphinx-prompt 1.3.0 docs
sphinxext-opengraph 0.4.2 docs
plotly 5.14.0 docs, examples
conda-lock 2.1.1 maintenance

...

So I just continued down the list, starting with
Code: [Select]
pip3 install -U cython
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4862
  • Have you played my board game?
    • Rival Troops
Re: Raspberry Pi and Python
« Reply #7 on: December 01, 2023, 22:29:18 »
Additionally, I installed cargo and rust, because they were mentioned as requirements for ruff. I got multiple errors and warnings when trying to install ruff the first time, so I tried these: 

Code: [Select]
~ $ pip3 install -U cargo
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting cargo
  Downloading https://www.piwheels.org/simple/cargo/cargo-0.3-py3-none-any.whl (7.2 kB)
Installing collected packages: cargo
Successfully installed cargo-0.3

Code: [Select]
~ $ pip3 install -U rust
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting rust
  Downloading https://www.piwheels.org/simple/rust/RUST-1.3.1-py3-none-any.whl (49 kB)
     |████████████████████████████████| 49 kB 187 kB/s
Collecting pysam
  Downloading https://www.piwheels.org/simple/pysam/pysam-0.22.0-cp39-cp39-linux_armv6l.whl (17.5 MB)
     |████████████████████████████████| 17.5 MB 15 kB/s
Requirement already satisfied: matplotlib in ./.local/lib/python3.9/site-packages (from rust) (3.8.2)
Requirement already satisfied: numpy in ./.local/lib/python3.9/site-packages (from rust) (1.26.2)
Requirement already satisfied: cycler>=0.10 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (0.12.1)
Requirement already satisfied: importlib-resources>=3.2.0 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (6.1.1)
Requirement already satisfied: kiwisolver>=1.3.1 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (1.4.5)
Requirement already satisfied: contourpy>=1.0.1 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (1.2.0)
Requirement already satisfied: pillow>=8 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (10.1.0)
Requirement already satisfied: fonttools>=4.22.0 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (4.45.1)
Requirement already satisfied: python-dateutil>=2.7 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (2.8.2)
Requirement already satisfied: pyparsing>=2.3.1 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (3.1.1)
Requirement already satisfied: packaging>=20.0 in ./.local/lib/python3.9/site-packages (from matplotlib->rust) (23.2)
Requirement already satisfied: zipp>=3.1.0 in ./.local/lib/python3.9/site-packages (from importlib-resources>=3.2.0->matplotlib->rust) (3.17.0)
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.7->matplotlib->rust) (1.16.0)
Installing collected packages: pysam, rust
Successfully installed pysam-0.22.0 rust-1.3.1
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)