openairplay / airplay2-receiver

AirPlay 2 Receiver - Python implementation
2.15k stars 134 forks source link

Cannot run docker image: ModuleNotFoundError: No module named 'av' #71

Closed FlixFlix closed 2 years ago

FlixFlix commented 2 years ago

The problem

Built the image per the instructions. When attempting docker run, I get: [ ok ] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon. Traceback (most recent call last): File "ap2-receiver.py", line 25, in <module> from ap2.connections.stream import Stream File "/airplay2/ap2/connections/stream.py", line 5, in <module> from .audio import AudioRealtime, AudioBuffered File "/airplay2/ap2/connections/audio.py", line 7, in <module> import av ModuleNotFoundError: No module named 'av'

What commit exhibits the issue?

504614f

Was there a last known working commit?

No response

What type of installation are you running?

Docker

With which python3 version do you run Receiver?

3.9.2

OS the receiver runs on

Raspberry Pi OS

OS the sender runs

Raspberry Pi OS

Which sender client was used

No response

Command invocation

docker run -it --rm --device /dev/snd --net host --volume pwd/pairings/:/airplay2/pairings/ ap2-receiver

Please include --debug output which helps to illustrate the problem

[ ok ] Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon. Traceback (most recent call last): File "ap2-receiver.py", line 25, in from ap2.connections.stream import Stream File "/airplay2/ap2/connections/stream.py", line 5, in from .audio import AudioRealtime, AudioBuffered File "/airplay2/ap2/connections/audio.py", line 7, in import av ModuleNotFoundError: No module named 'av'

Additional information

Built docker image using the command in readme.md. Only one error (red): debconf: delaying package configuration, since apt-utils is not installed. apt-utils is, in fact, installed though. Module av is also installed on the host, although not sure if that's relevant even.

oppermax commented 2 years ago

@FlixFlix any progress? I'm faced with the exact same issue 😊

Shjba commented 2 years ago

Same issue here. Theres nothing left to be added.

m3brown commented 2 years ago

This bug appears to have been introduced by commit 1bb03ca0bb0f8be96658aad936061e928b6fd77f (PR link), I can't recreate it in earlier commits.

I'm a bit perplexed by what's happening, but I have a consistent/quick way of reproducing it on my M1 Mac:

docker build -f docker/Dockerfile -t ap2-receiver .
docker run -it --entrypoint bash ap2-receiver  # launch a bash shell

# commands to run in the bash shell
pip3 freeze | grep av   # av should be in the freeze output, but it's not...

# you can see python3.7 site-packages has the av files
root@e397a60f713e:/# ls -l /usr/lib/python3.7/site-packages/
total 8
drwxr-xr-x 11 root root 4096 May  3 18:24 av
drwxr-xr-x  2 root root 4096 May  3 18:24 av-9.2.0-py3.7.egg-info

# Also notice the directory above is NOT in sys.path
root@0b83343bf3e4:/# python3 -m site
sys.path = [
    '/',
    '/usr/lib/python37.zip',
    '/usr/lib/python3.7',
    '/usr/lib/python3.7/lib-dynload',
    '/usr/local/lib/python3.7/dist-packages',
    '/usr/lib/python3/dist-packages',
]

# All the other packages are in two other directories that ARE in sys.path

root@e397a60f713e:/# ls /usr/lib/python3/dist-packages/
Crypto                            keyring
PyAudio-0.2.11.egg-info                   keyring-17.1.1.egg-info
PyGObject-3.30.4.egg-info                 keyrings
SecretStorage-2.3.1.egg-info                  keyrings.alt-3.1.1.egg-info
__pycache__                       pip
_cffi_backend.cpython-37m-aarch64-linux-gnu.so        pip-18.1.egg-info
_dbus_bindings.cpython-37m-aarch64-linux-gnu.so       pkg_resources
_dbus_glib_bindings.cpython-37m-aarch64-linux-gnu.so  pyaudio.py
_portaudio.cpython-36m-aarch64-linux-gnu.so       pycrypto-2.6.1.egg-info
_portaudio.cpython-37m-aarch64-linux-gnu.so       pygtkcompat
asn1crypto                        pyxdg-0.25.egg-info
asn1crypto-0.24.0.egg-info                secretstorage
cryptography                          setuptools
cryptography-2.6.1.egg-info               setuptools-40.8.0.egg-info
dbus                              six-1.12.0.egg-info
easy_install.py                       six.py
entrypoints.egg-info                      wheel
entrypoints.py                        wheel-0.32.3.egg-info
gi                            xdg

root@0b83343bf3e4:/# ls /usr/local/lib/python3.7/dist-packages/
Crypto                   ifaddr
__pycache__              ifaddr-0.1.7.dist-info
biplist                  netifaces-0.11.0.egg-info
biplist-1.0.3.egg-info           netifaces.cpython-37m-aarch64-linux-gnu.so
certifi                  numpy
certifi-2021.10.8.dist-info      numpy-1.21.6-py3.7.egg-info
charset_normalizer           pycryptodome-3.14.1.egg-info
charset_normalizer-2.0.12.dist-info  requests
data                     requests-2.27.1.dist-info
hexdump-3.3.egg-info             srptools
hexdump.py               srptools-1.0.1.dist-info
hkdf-0.0.3.egg-info          urllib3
hkdf.py                  urllib3-1.26.9.dist-info
idna                     zeroconf
idna-3.3.dist-info           zeroconf-0.38.3.dist-info

Removing --no-cache-dir from the Dockerfile pip install fixes the issue. Additionally, the av files move from /usr/lib/python3.7/site-packages/ to /usr/local/lib/python3.7/dist-packages/.

m3brown commented 2 years ago

I was able to track this down to a specific version of the av library. With --no-cache-dir enabled in the pip install, everything works fine with av==8.1.0 and fails with av==9.0.0, which was tagged in March 2022 (av release history).

However, version 8.1.0 doesn't appear to work properly on ARM, it gives an error first reported in 2019 (av github issue)

>>> import av
eTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/av/__init__.py", line 9, in <module>
    from av._core import time_base, pyav_version as __version__, library_versions
ImportError: /usr/lib/aarch64-linux-gnu/libgomp.so.1: cannot allocate memory in static TLS block

This can be worked around with LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1