St7789, Python, Legacy OS, can't get it to work?

I have a 1.54" SPI Colour Square LCD (240x240) Breakout wired up to a Pi Zero 2W running Legacy OS. I have run
sudo pip install st7789

kyrie@raspberrypi:~ $ sudo apt install python3-rpi.gpio python3-spidev python3-pip python3-pil python3-numpy
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-numpy is already the newest version (1:1.19.5-1).
python3-pil is already the newest version (8.1.2+dfsg-0.3+deb11u2).
python3-pil set to manually installed.
python3-rpi.gpio is already the newest version (0.7.0-0.2+b1).
python3-pip is already the newest version (20.3.4-4+rpt1+deb11u1).
python3-spidev is already the newest version (20200602~200721-1).
The following package was automatically installed and is no longer required:
  libfuse2
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
kyrie@raspberrypi:~ $ sudo pip3 install st7789
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: st7789 in /usr/local/lib/python3.9/dist-packages (1.0.1)
Requirement already satisfied: numpy>=1.26.4 in /usr/local/lib/python3.9/dist-packages (from st7789) (2.0.2)
Requirement already satisfied: gpiod in /usr/local/lib/python3.9/dist-packages (from st7789) (2.2.3)
Requirement already satisfied: spidev>=3.6 in /usr/local/lib/python3.9/dist-packages (from st7789) (3.6)
Requirement already satisfied: gpiodevice>=0.0.4 in /usr/local/lib/python3.9/dist-packages (from st7789) (0.0.5)
kyrie@raspberrypi:~ $ 

Running any of the examples gets me the following

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/numpy/_core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/usr/local/lib/python3.9/dist-packages/numpy/_core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/usr/local/lib/python3.9/dist-packages/numpy/_core/overrides.py", line 8, in <module>
    from numpy._core._multiarray_umath import (
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/numpy/__init__.py", line 114, in <module>
    from numpy.__config__ import show as show_config
  File "/usr/local/lib/python3.9/dist-packages/numpy/__config__.py", line 4, in <module>
    from numpy._core._multiarray_umath import (
  File "/usr/local/lib/python3.9/dist-packages/numpy/_core/__init__.py", line 49, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/usr/bin/python3"
  * The NumPy version is: "2.0.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libopenblas.so.0: cannot open shared object file: No such file or directory


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kyrie/scrolling-text.py", line 7, in <module>
    import st7789
  File "/usr/local/lib/python3.9/dist-packages/st7789/__init__.py", line 26, in <module>
    import numpy
  File "/usr/local/lib/python3.9/dist-packages/numpy/__init__.py", line 119, in <module>
    raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.
>>> 

I think you hit an error that is related to not using a virtual environment. There is a conflict of the numpy-version necessary for the pip-packages, and the numpy version provided by the PiOS.

Virtual environments are a problem in the sense that they add some additional steps for you, but they were created because of exactly these kind of conflicts.

Ok, so I have no choice but to use a Virtual Environment? There is no mention of this in the install instructions? Or if the installer is written for that type of install etc. It’s why I went with a Legacy install.
@hel

Legacy has nothing to do with virtual environments. The only difference is that you are now kind of forced to use virtual environments. The legacy Debian, PiOS and other Linux flavors just let you do what you want, regardless if this causes problems or not. Virtual environments were already recommended many years ago…

BTW: I know this same numpy error very well, I also ran into this problem in the past. I think I deinstalled the PiOS version. Then pip pulls in a version that works. But I am not 100% sure.

I used Legacy based on the assumption that the installer was pre virtual environments. I had two 1.54 240 x 240 LCD breakouts running just fine on my Pi 400. I was trying to redo that setup, so here I am.
I’ll do some more testing and post the results. I may go back one version before Bookworm on my Pi 400.

It is probably true that the installer is β€œpre virtual environments”. But that does not imply that you don’t run into problems. The installer does not pull in software-versions that were current in the past at the same time the installer was written. So in other words: at the time the installer had been written, everything will probably have worked fine. But the software it pulls in changed over time and now has other dependencies.

Yes, I totally agree with what you are saying. I am going to have a go at a virtual setup.
I have a Pi Zero with three of the 0.96" SPI Colour LCD (160x80) Breakouts wired up to SPI1. It is running Buster, which was the os of choice when I set it up.
Three display weather graphing setup - Discussion / Projects - Pimoroni Buccaneers
I’m wanting to switch to bigger displays, st7789 based. I cloned the card first off. Then tried to run the st7789 installer. I was thinking this would be the easiest way. Once I got the bigger display running I’d just edit my current file.
That got me a no module named st7889 error in Thonny when i ran an example. More messing about got me other errors like I posted above. I’m going to revisit that and take some notes that I can post here.
The next step was to install that same version of Buster on a spare Pi Zero, and try again with a fresh install. I got basically the same as with the cloned card. Nothing I did worked?

That’s when I started this thread. I have setup a virtual setup in the past, distant past, lol. Can you run code in Thonny, in the virtual enviroment?

My first step in my fresh start will be to try and set this up again.
My Pi 400 CPU info display - Discussion / Projects - Pimoroni Buccaneers

Bangs head against wall. =(

kyrie@Pi400:~ $ sudo apt install python3-venv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-venv is already the newest version (3.11.2-1+b1).
The following package was automatically installed and is no longer required:
  libwlroots12
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
kyrie@Pi400:~ $ python3 -m venv st7789
kyrie@Pi400:~ $ ls
Bookshelf  Downloads  Public         st7789-python     Videos
Desktop    Music      rv3028-python  Templates
Documents  Pictures   st7789         trackball-python
kyrie@Pi400:~ $ ls st7789
bin  include  lib  lib64  pyvenv.cfg
kyrie@Pi400:~ $ source st7789/bin/activate
(st7789) kyrie@Pi400:~ $ sudo apt-get install python-rpi.gpio python-spidev python-pip python-pil python-numpy
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package python-numpy is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package python-pip is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  python3-pip

Package python-rpi.gpio is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package python-pil is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package python-spidev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-rpi.gpio' has no installation candidate
E: Package 'python-spidev' has no installation candidate
E: Package 'python-pip' has no installation candidate
E: Package 'python-pil' has no installation candidate
E: Package 'python-numpy' has no installation candidate
(st7789) kyrie@Pi400:~ $ sudo pip install st7789
error: externally-managed-environment

Γ— This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    For more information visit http://rptl.io/venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
(st7789) kyrie@Pi400:~ $ apt install python3-st7789
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
(st7789) kyrie@Pi400:~ $ 


The fun continues.

kyrie@Pi400:~ $ cd st7789-python
kyrie@Pi400:~/st7789-python $ sudo ./install.sh
Installing st7789...

⚠ FATAL: Script should not be run as root. Try './install.sh'

kyrie@Pi400:~/st7789-python $  ./install.sh
Installing st7789...

This script should be run in a virtual Python environment.
Would you like us to create and/or use a default one? [y/N] y

Creating a new virtual Python environment in /home/kyrie/.virtualenvs/pimoroni, please wait...

Checking for /home/kyrie/Pimoroni/auto_venv.sh

Creating /home/kyrie/Pimoroni/auto_venv.sh


Checking Dependencies. Please wait...
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: toml in /usr/lib/python3/dist-packages (0.10.2)

Installing for Python 3.11.2...


Installing stable library from pypi.

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting st7789
  Downloading https://www.piwheels.org/simple/st7789/st7789-1.0.1-py3-none-any.whl (10 kB)
Collecting gpiod
  Downloading gpiod-2.2.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (100 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.4/100.4 kB 754.1 kB/s eta 0:00:00
Collecting gpiodevice>=0.0.4
  Downloading https://www.piwheels.org/simple/gpiodevice/gpiodevice-0.0.5-py3-none-any.whl (9.2 kB)
Collecting numpy>=1.26.4
  Downloading numpy-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (14.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.3/14.3 MB 2.0 MB/s eta 0:00:00
Collecting spidev>=3.6
  Downloading spidev-3.6.tar.gz (11 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: spidev
  Building wheel for spidev (pyproject.toml) ... done
  Created wheel for spidev: filename=spidev-3.6-cp311-cp311-linux_aarch64.whl size=42605 sha256=918eece435b05380775d37324669ea8ab7c6324132a2ffd1000cb908fcba077f
  Stored in directory: /home/kyrie/.cache/pip/wheels/44/f9/7b/01bb1f281eedaaa562943e27c78dee683ee6e7f3bf2f437101
Successfully built spidev
Installing collected packages: spidev, numpy, gpiod, gpiodevice, st7789
  Attempting uninstall: spidev
    Found existing installation: spidev 3.5
    Not uninstalling spidev at /usr/lib/python3/dist-packages, outside environment /home/kyrie/.virtualenvs/pimoroni
    Can't uninstall 'spidev'. No files were found to uninstall.
  Attempting uninstall: numpy
    Found existing installation: numpy 1.24.2
    Not uninstalling numpy at /usr/lib/python3/dist-packages, outside environment /home/kyrie/.virtualenvs/pimoroni
    Can't uninstall 'numpy'. No files were found to uninstall.
Successfully installed gpiod-2.2.3 gpiodevice-0.0.5 numpy-2.2.1 spidev-3.6 st7789-1.0.1
Done!

Using config.txt in /boot/firmware

Running setup commands...

Running: ""


Would you like to copy examples to /home/kyrie/Pimoroni/st7789? [y/N] y
Copying examples to /home/kyrie/Pimoroni/st7789
Done!

Would you like to generate documentation? [y/N] y
Installing pdoc. Please wait...
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pdoc
  Downloading https://www.piwheels.org/simple/pdoc/pdoc-15.0.1-py3-none-any.whl (144 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 144.2/144.2 kB 532.0 kB/s eta 0:00:00
Requirement already satisfied: Jinja2>=2.11.0 in /usr/lib/python3/dist-packages (from pdoc) (3.1.2)
Requirement already satisfied: pygments>=2.12.0 in /usr/lib/python3/dist-packages (from pdoc) (2.14.0)
Requirement already satisfied: MarkupSafe>=1.1.1 in /usr/lib/python3/dist-packages (from pdoc) (2.1.2)
Installing collected packages: pdoc
Successfully installed pdoc-15.0.1
Generating documentation.

Documentation saved to /home/kyrie/Pimoroni/st7789/docs
Done!


All done!
If this is your first time installing you should reboot for hardware changes to take effect.
Find uninstall steps in /home/kyrie/Pimoroni/st7789/uninstall.sh

kyrie@Pi400:~/st7789-python $ cd examples
kyrie@Pi400:~/st7789-python/examples $ python3 scrolling-text.py
Traceback (most recent call last):
  File "/home/kyrie/st7789-python/examples/scrolling-text.py", line 7, in <module>
    import st7789
ModuleNotFoundError: No module named 'st7789'
kyrie@Pi400:~/st7789-python/examples $ 


Are you aware that you have two virtual envs now, one that you created and one that the installer created? Before running the examples, you should deactivate your manually created environment and activate the v-env of the installer.

No I wasn’t aware? I was trying to follow this guide.
Overview | Python Virtual Environment Usage on Raspberry Pi | Adafruit Learning System

@Hel
What is the correct way to install the Python driver
pimoroni/st7789-python: Python library to control an ST7789 240x240 1.3" TFT LCD display.
for this,
1.54" SPI Colour Square LCD (240x240) Breakout
In Bookworm?

I found a way to get it to work.
I installed the latest Pi OS 64 bit (Bookworm).
Then I disabled the virtual environment.
sudo rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED
Then ran the installer.
sudo pip install st7789
Then ran the scrolling text example. It now runs fine with no error messages.

Scold me if you want but it’s what worked, with minimal fiddling around.

Well, keep your fingers crossed that some other installer that you run (or a system update) does not pull in something incompatible.

I usually do what you do on small, single application systems (where I usually also disable automatic system updates). But everywhere I run multiple (python) applications, I learned to be very conservative.

Sorry for the slow reply - I’ve been on holiday for the last couple of weeks and it’s taking me a moment to catch up!

What is the correct way to install the Python driver
pimoroni/st7789-python: Python library to control an ST7789 240x240 1.3" TFT LCD display.
for this,
1.54" SPI Colour Square LCD (240x240) Breakout
In Bookworm?

I believe the most recent version of the st7789 installer installs into a virtual environment (if you don’t have one, it will set one up for you).

Try
git clone https://github.com/pimoroni/st7789-python
cd st7789-python
./install.sh

You’ll then need to switch to your virtual environment before running the examples with:

source ~/.virtualenvs/pimoroni/bin/activate

Looks like we could indeed do with updating the readme to be a bit more helpful here!

1 Like

Ok, thanks Hel.
I’m reflashing my SD card with The latest Pi OS (Bookworm) 64 bit. I’ll have another go at it with a fresh image and post back the results.

1 Like

It is important that you install everything into the same virtual environment. During your first go, you installed part of the packages in one environment and then the ST7789 in a second venv. If there is not a single install script/command that takes care of all packages, you really have to read the output of each command to understand where parts of your code are installed.

Ok, that worked. I’m getting a message about text size being depreciated, but I’m getting the scrolling text on a display when run from the virtual environment.