仮想環境
当方のiMacでなぜかpipが呼べないという信じられない事態に陥っていたので、venvで構築しています。
本筋に関係ない仮想環境導入までの話
仮想環境に乗り換えるまでの悪あがき
% pip install manimgl
zsh: command not found: pip
念の為pythonが入っているか確認。
% brew install python3
==> Auto-updating Homebrew...
(中略)
Error: No such file or directory @ rb_check_realpath_internal - /usr/local/Cellar/julia/1.11.2
どこかで見たget-pip.py
を入れる手法で解決を試みる。
% python3 get-pip.py
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.
If you wish to install a Python library that isn't in Homebrew,
use a virtual environment:
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install xyz
If you wish to install a Python application that isn't in Homebrew,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. You can install pipx with
brew install pipx
You may restore the old behavior of pip by passing
the '--break-system-packages' flag to pip, or by adding
'break-system-packages = true' to your pip.conf file. The latter
will permanently disable this error.
If you disable this error, we STRONGLY recommend that you additionally
pass the '--user' flag to pip, or set 'user = true' in your pip.conf
file. Failure to do this can result in a broken Homebrew installation.
......
このあとpipxを使ってみたが、ダウンロードはできた素ぶりを見せるものの、結局manimglを読んでも返事がない。
仮想環境に乗り換え
venvとか今までおまじないだとしか思っておらず、まともに触ったことがなかったので、ここで克服してみる。
参考:https://qiita.com/shun_sakamoto/items/7944d0ac4d30edf91fde
- 作業ディレクトリに移動
-
python3 -m venv venv
で仮想環境を新規構築 . venv/bin/activate
pip3 install manimgl
余談ここまで
仮想環境上での格闘記録
ファイルをtutorial.py
として実行してみる。
ModuleNotFoundError: No module named 'manim_imports_ext'
とかいうエラーが出てきた。
調べてみるとmanim_imports_ext
はhttps://github.com/3b1b/videos/blob/master/manim_imports_ext.py にある形で書かれていて、別に配布しているものでもなさそう。1
ワーキングディレクトリにmanim_imports_ext.py
を作成。
from manimlib import *
from manimlib.mobject.svg.old_tex_mobject import *
from custom.backdrops import *
from custom.banner import *
from custom.characters.pi_creature import *
from custom.characters.pi_creature_animations import *
from custom.characters.pi_creature_scene import *
from custom.deprecated import *
from custom.drawings import *
from custom.end_screen import *
from custom.filler import *
from custom.logo import *
from custom.opening_quote import *
これで回してみよう。
python3 tutorial.py
Traceback (most recent call last):
(中略)
ModuleNotFoundError: No module named 'pkg_resources'
今度はhttps://qiita.com/HidKamiya/items/619ca56cee9a5005d5c4 にしたがって。
% pip install --upgrade setuptools
Collecting setuptools
Using cached setuptools-75.6.0-py3-none-any.whl.metadata (6.7 kB)
Using cached setuptools-75.6.0-py3-none-any.whl (1.2 MB)
Installing collected packages: setuptools
Successfully installed setuptools-75.6.0
% python3 tutorial.py
Traceback (most recent call last):
(中略)
ModuleNotFoundError: No module named 'pyrr'
めげない、しょげない、泣いちゃだめ〜
% pip3 install pyrr
Successfully installed multipledispatch-1.0.0 pyrr-0.10.3
% python3 tutorial.py
Traceback (most recent call last):
(中略)
ModuleNotFoundError: No module named 'audioop'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
(中略)
ModuleNotFoundError: No module named 'pyaudioop'
% pip3 install pyaudioop
ERROR: Could not find a version that satisfies the requirement pyaudioop (from versions: none)
ERROR: No matching distribution found for pyaudioop
なんでないんや。
audioopなんて削除されとるぞ。https://docs.python.org/ja/3.11/library/audioop.html
ダウングレードしないといけないらしい。
流石にめんどい。