Closed9

Debian GNU/Linux 12 (bookworm)メモ

ijiwarunahelloijiwarunahello

環境

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm
$ python -V
Python 3.11.2
ijiwarunahelloijiwarunahello

音声再生

playsound

依存ライブラリをインストール

sudo apt install libgirepository1.0-dev
pip install pygobject

pygobjectでエラー

$ pip install pygobject
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pygobject
  Using cached PyGObject-3.46.0.tar.gz (723 kB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [45 lines of output]
      Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple, https://www.piwheels.org/simple
      Collecting setuptools
        Using cached https://www.piwheels.org/simple/setuptools/setuptools-68.2.2-py3-none-any.whl (807 kB)
      Collecting wheel
        Using cached https://www.piwheels.org/simple/wheel/wheel-0.41.2-py3-none-any.whl (64 kB)
      Collecting pycairo
        Downloading pycairo-1.25.1.tar.gz (347 kB)
           ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 347.1/347.1 kB 3.1 MB/s eta 0:00:00
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Installing backend dependencies: started
        Installing backend dependencies: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'done'
      Building wheels for collected packages: pycairo
        Building wheel for pycairo (pyproject.toml): started
        Building wheel for pycairo (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error

        × Building wheel for pycairo (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [15 lines of output]
            running bdist_wheel
            running build
            running build_py
            creating build
            creating build/lib.linux-aarch64-cpython-311
            creating build/lib.linux-aarch64-cpython-311/cairo
            copying cairo/__init__.py -> build/lib.linux-aarch64-cpython-311/cairo
            copying cairo/__init__.pyi -> build/lib.linux-aarch64-cpython-311/cairo
            copying cairo/py.typed -> build/lib.linux-aarch64-cpython-311/cairo
            running build_ext
            Package cairo was not found in the pkg-config search path.
            Perhaps you should add the directory containing `cairo.pc'
            to the PKG_CONFIG_PATH environment variable
            Package 'cairo', required by 'virtual:world', not found
            Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.15.10']' returned non-zero exit status 1.
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for pycairo
      Failed to build pycairo
      ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

参考:

https://stackoverflow.com/questions/69200217/why-is-the-playsound-function-not-able-to-play-my-mp3-file-in-python

ijiwarunahelloijiwarunahello

先にplaysoundを入れてみる

$ pip install playsound
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.

bookwormからpipでグローバルな環境にインストールできない(aptを使う)ようになっているらしい

https://gihyo.jp/admin/serial/01/ubuntu-recipe/0767

venvで仮想環境を作ってインストール

sudo apt install python3-venv
python -m venv .venv
source .venv/bin/activate
pip install playsound

テスト

import playsound

playsound.playsound("/usr/share/sounds/alsa/Front_Center.wav")
$ python soundplay_test.py
playsound is relying on another python subprocess. Please use `pip install pygobject` if you want playsound to run more efficiently.
<ここから固まって動かない>
^CTraceback (most recent call last):
  File "/home/iri/workspace/scripts/soundplay_test.py", line 3, in <module>
    playsound.playsound("/usr/share/sounds/alsa/Front_Center.wav")
  File "/home/iri/workspace/scripts/.venv/lib/python3.11/site-packages/playsound.py", line 254, in <lambda>
    playsound = lambda sound, block = True: _playsoundAnotherPython('/usr/bin/python3', sound, block, macOS = False)
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/iri/workspace/scripts/.venv/lib/python3.11/site-packages/playsound.py", line 229, in _playsoundAnotherPython
    t.join()
  File "/home/iri/workspace/scripts/.venv/lib/python3.11/site-packages/playsound.py", line 216, in join
    super().join(timeout)
  File "/usr/lib/python3.11/threading.py", line 1112, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.11/threading.py", line 1132, in _wait_for_tstate_lock
    if lock.acquire(block, timeout):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
ijiwarunahelloijiwarunahello

依存パッケージらしき物をインストール

sudo apt install libcairo2-dev

参考:

https://github.com/pygobject/pycairo/issues/326#issuecomment-1619535605

$ pip install pygobject
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pygobject
  Using cached PyGObject-3.46.0.tar.gz (723 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pycairo>=1.16.0 (from pygobject)
  Using cached pycairo-1.25.1-cp311-cp311-linux_aarch64.whl
Building wheels for collected packages: pygobject
  Building wheel for pygobject (pyproject.toml) ... done
  Created wheel for pygobject: filename=PyGObject-3.46.0-cp311-cp311-linux_aarch64.whl size=788239 sha256=0c5303780bc32c3ecabf2d1028d6ac62cfd91d299f12079702d438c6264cb6a0
  Stored in directory: /home/iri/.cache/pip/wheels/e6/34/e9/dc9e5f3e9d4a931b21414c32ad5df5e478afd6f3f9cb54e0ca
Successfully built pygobject
Installing collected packages: pycairo, pygobject
Successfully installed pycairo-1.25.1 pygobject-3.46.0

通った!

が依然再生できない(playsound()を実行すると何もメッセージが出ず固まる)ので一旦諦める

ijiwarunahelloijiwarunahello

固定IP

bullseyeから、dhcpからNetworkManagerに変わっており、nmcliコマンドを使ってワンラインで設定できる。

構成例:WiFi→ネットワーク、有線LAN→ローカルエリア接続

無線(wlan0):

sudo nmcli connection modify <YOUR_WIFI_SSID> ipv4.addresses 192.168.10.100/24 ipv4.gateway 192.168.10.1 ipv4.method manual ipv4.route-metric 10

有線:

sudo nmcli con mod "Wired connection 1" ipv4.addresses "192.168.0.2/24" ipv4.gateway "192.168.0.1" ipv4.method manual ipv4.route-metric 20

無線のメトリックを有線より小さい値にすることで、無線LANインターフェースが優先になる。

再起動:

sudo nmcli con down "Wired connection 1" && sudo nmcli con up "Wired connection 1"
sudo nmcli con down <YOUR_WIFI_SSID> && sudo nmcli con up <YOUR_WIFI_SSID>

参考:

https://zenn.dev/technicarium/articles/9d3ee150a3cf04

このスクラップは2ヶ月前にクローズされました