Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

まずは pillow-avif-plugin をインストールする

通常gentooではpythonパッケージもemergeでインストールするがgentooの公式パッケージには pillow-avif-plugin が存在しないので pip で強制的に入れる

普通にインストールしようとすると以下のようにemergeで管理されているからインストールさせないよ、やりたいならvenv作ってやってねと出てくる

Code Block
languagebash
themeMidnight
titlepip install error
linenumberstrue
collapsetrue
$ pip install pillow-avif-plugin 
error: externally-managed-environment

× This environment is externally managed
╰─> 
    The system-wide Python installation in Gentoo should be maintained
    using the system package manager (e.g. emerge).
    
    If the package in question is not packaged for Gentoo, please
    consider installing it inside a virtual environment, e.g.:
    
    python -m venv /path/to/venv
    . /path/to/venv/bin/activate
    pip install mypackage
    
    To exit the virtual environment, run:
    
    deactivate
    
    The virtual environment is not deleted, and can be re-entered by
    re-sourcing the activate file.

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.


$ pip install pillow-avif-plugin --break-system-packages

ので、最後の行にあるように --break-syste-packages オプションを付けて実行する

とりあえず自分の手元ではこれが原因で環境が崩壊するようなことはなかった


続いてMComixをavifに対応させるためにコードに一行追加する

改変するファイルがどこにあるか探すために以下のコマンドを実行する

Code Block
languagebash
themeMidnight
titlesearch image_tools.py
linenumberstrue
collapsetrue
$ sudo find /usr -type f -name image_tools.py
Password: 
/usr/lib/python3.11/site-packages/mcomix/image_tools.py
/usr/lib/python3.10/site-packages/mcomix/image_tools.py

自分の環境ではこの2箇所に存在するようだ

利用しているpythonのバージョンに応じて複数出てくると思われるが今現在利用しているバージョンのものだけ書き換えればいいと思われる

心配なら全部書き換えてしまってもたぶん問題ない(pythonのメジャーバージョンが異ならない限り

編集する箇所は一箇所だけ

Code Block
languagebash
themeMidnight
titleedit image_tools.py
linenumberstrue
collapsetrue
$ cp /usr/lib/python3.11/site-packages/mcomix/image_tools.py /tmp/
$ sudo vim /usr/lib/python3.11/site-packages/mcomix/image_tools.py
$ diff -u /tmp/image_tools.py /usr/lib/python3.11/site-packages/mcomix/image_tools.py
--- /tmp/image_tools.py 2023-06-15 16:32:25.545656130 +0900
+++ /usr/lib/python3.11/site-packages/mcomix/image_tools.py     2023-06-15 15:52:27.785014317 +0900
@@ -1,5 +1,7 @@
 """image_tools.py - Various image manipulations."""
 
+import pillow_avif
+
 import operator
 from gi.repository import GLib, GdkPixbuf, Gdk, Gtk
 import PIL

このように import を一行追加するだけ

これでMComixでもavifファイルを表示できるようになった


参考文献

https://qiita.com/mimaburao/items/d48c4340ce7947b81b7e