pimoroni / pidi-spotify

MIT License
47 stars 12 forks source link

Cannot load numpy #18

Open Jestergum opened 2 years ago

Jestergum commented 2 years ago

Hi,

Pidi-spotify won't work, as soon as i enable the --onevent hook in /etc/default/raspotify and restart, spotify won't play correctly anymore.

So i'm a complete python noob, but have been using rpi's in hobby projects. This is my first time declaring an issue, so if you have any tips please feel free to give em.

I've located the problem to here so far, cannot find any other issues

The issue lies with pidi-spotify not finding numpy.

journalctl gives me this for pidi_spotify.service :

import numpy as np ModuleNotFoundError: No module named 'numpy'

I'm running a rpi zero, the numpy installation took quite a while. I left it running and went to sleep, when i woke up it said installation succesfull.

also this does seem to work : python3 -c "import numpy; print(numpy.version)" 1.21.5

Versions :  Hardware :  processor : 0 model name : ARMv6-compatible processor rev 7 (v6l) BogoMIPS : 997.08 Features : half thumb fastmult vfp edsp java tls CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xb76 CPU revision : 7 Hardware : BCM2835 Revision : 9000c1 Serial : 000000009dc87452 Model : Raspberry Pi Zero W Rev 1.1

Debian PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Kernel : Linux raspberrypirate 5.10.63+ #1496 Wed Dec 1 15:57:05 GMT 2021 armv6l GNU/Linux

The only thing i realised is that my raspotify isn't up to date apt-cache policy raspotify raspotify: Installed: 0.16.0~librespot.v0.1.3-37-g0adb851 Candidate: 0.31.11.1~librespot.v0.3.1-60-g616809b Version table: 0.31.11.1~librespot.v0.3.1-60-g616809b 500 500 https://dtcooper.github.io/raspotify raspotify/main armhf Packages *** 0.16.0~librespot.v0.1.3-37-g0adb851 100 100 /var/lib/dpkg/status

But i'm not sure if this will solve the numpy problem. Any ideas anyone?

EDIT : updating raspotify isn't an option since i'll need to go to bullseye and i don't think pidi-spotify supports that

Jestergum commented 2 years ago

More logs

systemctl status raspotify ● raspotify.service - Raspotify    Loaded: loaded (/lib/systemd/system/raspotify.service; enabled; vendor preset: enabled)    Active: active (running) since Sun 2022-02-20 20:31:02 CET; 2min 22s ago   Process: 13333 ExecStartPre=/bin/mkdir -m 0755 -p /var/cache/raspotify (code=exited, status=0/SUCCESS)   Process: 13334 ExecStartPre=/bin/chown raspotify:raspotify /var/cache/raspotify (code=exited, status=0/SUCCESS)  Main PID: 13335 (librespot)     Tasks: 44 (limit: 877)    CGroup: /system.slice/raspotify.service            ├─13335 /usr/bin/librespot --name rasputin --device-type speaker --backend alsa --bitrate 320 --disable-audio-cache --enable-volume-normalisation --volume-ctrl linear --initial-volume 100 --onevent pidi_spotify --hook            ├─13391 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13393 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13394 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13395 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13404 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13405 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13406 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13407 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13411 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13412 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13413 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13414 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13415 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13416 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13417 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13418 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13419 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13421 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13422 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13423 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13424 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13425 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13426 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13427 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13428 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13429 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13430 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13432 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13433 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13434 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13435 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13436 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13437 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13438 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13439 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13441 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13442 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13443 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13444 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            ├─13445 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook            └─13446 /usr/bin/python3 /usr/local/bin/pidi_spotify --hook

Feb 20 20:33:13 raspberrypirate librespot[13335]: [2022-02-20T19:33:13Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"DURATION_MS": "215733", "TRACK_ID": "5lK18Pt33xNudq4qYDxIm8", "PLAYER_EVENT": "playing", "POSITION_MS": "17877"} Feb 20 20:33:14 raspberrypirate librespot[13335]: [2022-02-20T19:33:14Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"PLAYER_EVENT": "playing", "DURATION_MS": "215733", "POSITION_MS": "18063", "TRACK_ID": "5lK18Pt33xNudq4qYDxIm8"} Feb 20 20:33:16 raspberrypirate librespot[13335]: [2022-02-20T19:33:16Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"DURATION_MS": "215733", "PLAYER_EVENT": "playing", "TRACK_ID": "5lK18Pt33xNudq4qYDxIm8", "POSITION_MS": "18248"} Feb 20 20:33:17 raspberrypirate librespot[13335]: ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred Feb 20 20:33:17 raspberrypirate librespot[13335]: [2022-02-20T19:33:17Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"TRACK_ID": "5lK18Pt33xNudq4qYDxIm8", "PLAYER_EVENT": "playing", "POSITION_MS": "18364", "DURATION_MS": "215733"} Feb 20 20:33:19 raspberrypirate librespot[13335]: [2022-02-20T19:33:19Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"PLAYER_EVENT": "playing", "POSITION_MS": "18550", "TRACK_ID": "5lK18Pt33xNudq4qYDxIm8", "DURATION_MS": "215733"} Feb 20 20:33:20 raspberrypirate librespot[13335]: [2022-02-20T19:33:20Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"PLAYER_EVENT": "playing", "DURATION_MS": "215733", "POSITION_MS": "18666", "TRACK_ID": "5lK18Pt33xNudq4qYDxIm8"} Feb 20 20:33:22 raspberrypirate librespot[13335]: [2022-02-20T19:33:22Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"PLAYER_EVENT": "playing", "DURATION_MS": "215733", "TRACK_ID": "5lK18Pt33xNudq4qYDxIm8", "POSITION_MS": "18829"} Feb 20 20:33:22 raspberrypirate librespot[13335]: ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred Feb 20 20:33:23 raspberrypirate librespot[13335]: [2022-02-20T19:33:23Z INFO librespot::player_event_handler] Running ["pidi_spotify", "--hook"] with environment variables {"PLAYER_EVENT": "playing", "POSITION_MS": "18945", "DURATION_MS": "215733", "TRACK_ID": "5lK18Pt33xNudq4qYDxIm8"}

journalctl

Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: Traceback (most recent call last): Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/local/bin/pidi_spotify", line 11, in Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: load_entry_point('pidi-spotify==0.0.1', 'console_scripts', 'pidi_spotify')() Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 489, in load_entry_point Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: return get_distribution(dist).load_entry_point(group, name) Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2793, in load_entry_point Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: return ep.load() Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2411, in load Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: return self.resolve() Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2417, in resolve Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: module = import(self.module_name, fromlist=['name'], level=0) Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/local/lib/python3.7/dist-packages/pidi_spotify-0.0.1-py3.7.egg/pidi_spotify/init.py", line 15, in Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/local/lib/python3.7/dist-packages/pidi_spotify-0.0.1-py3.7.egg/pidi_spotify/st7789.py", line 6, in Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/local/lib/python3.7/dist-packages/pidi_display_st7789-0.1.2-py3.7.egg/pidi_display_st7789/init.py", line 2, in < Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: from ST7789 import ST7789 as ST7789, BG_SPI_CS_FRONT, ST7789_DISPOFF, ST7789_DISPON Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: File "/usr/local/lib/python3.7/dist-packages/ST7789-0.0.4-py3.7.egg/ST7789/init.py", line 23, in Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: import numpy as np Feb 19 09:07:42 raspberrypirate pidi_spotify[536]: ModuleNotFoundError: No module named 'numpy' Feb 19 09:07:42 raspberrypirate systemd[1]: pidi-spotify.service: Main process exited, code=exited, status=1/FAILURE Feb 19 09:07:42 raspberrypirate systemd[1]: pidi-spotify.service: Failed with result 'exit-code'. Feb 19 09:07:42 raspberrypirate systemd[1]: pidi-spotify.service: Service RestartSec=100ms expired, scheduling restart. Feb 19 09:07:42 raspberrypirate systemd[1]: pidi-spotify.service: Scheduled restart job, restart counter is at 4. Feb 19 09:07:42 raspberrypirate systemd[1]: Stopped PiDi Spotify Service. Feb 19 09:07:42 raspberrypirate systemd[1]: Started PiDi Spotify Service. Feb 19 09:07:43 raspberrypirate systemd[1]: systemd-hostnamed.service: Succeeded.

Jestergum commented 2 years ago

So i think i've narrowed it down to the Path. https://leemendelowitz.github.io/blog/how-does-python-find-packages.html

It has something to with debian being a different python build and not importing site-packages. I'm looking for a way to include these site-packages. The link describes something, but i don't know where to put it or call it.

`def getsitepackages(): """Returns a list containing all global site-packages directories (and possibly site-python).

For each directory present in the global ``PREFIXES``, this function
will find its `site-packages` subdirectory depending on the system
environment, and will return a list of full paths.
"""
sitepackages = []
seen = set()

for prefix in PREFIXES:
    if not prefix or prefix in seen:
        continue
    seen.add(prefix)

    if sys.platform in ('os2emx', 'riscos'):
        sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))
    elif os.sep == '/':
        sitepackages.append(os.path.join(prefix, "local/lib",
                                    "python" + sys.version[:3],
                                    "dist-packages"))
        sitepackages.append(os.path.join(prefix, "lib",
                                    "python" + sys.version[:3],
                                    "dist-packages"))
    else:
        sitepackages.append(prefix)
        sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
    if sys.platform == "darwin":
        # for framework builds *only* we add the standard Apple
        # locations.
        from sysconfig import get_config_var
        framework = get_config_var("PYTHONFRAMEWORK")
        if framework:
            sitepackages.append(
                    os.path.join("/Library", framework,
                        sys.version[:3], "site-packages"))
return sitepackages`

I've also found it to be possible to edit the ~/.profile But am not sure what to put there in order to inlude the site-packages or just numpy.

Gadgetoid commented 2 years ago

It's possible you have numpy installed in the users local packages, and the service is running under another user context.

IE: python3 -c "import numpy; print(numpy.version)" works but: sudo python3 -c "import numpy; print(numpy.version)" probably will not.

This might help:

sudo apt install python3-numpy
Jestergum commented 2 years ago

That works :) (i mean the import works, now i'm getting different errors :p) Thanks

I saw that one before but hesitated to use it. I didn't want to have two conflicting installs for python. My python knowledge isn't sufficient, so i've learned something new :D

Edit : I was messing with some settings and apparently high bitrate gives me ALSA underruns. The default setting is working fine Yaaay, tysm

Edit : Okay maybe not fine. Getting a lot of cpu load on my tiny pi zero w. htop shows pidi_spotify --hook several times all with 15% cpu load.