0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

macのBlenderのPythonにパッケージをインストールする方法

Last updated at Posted at 2025-02-23

概要

macOS Sequoia 15.3.1のBlender4.3に、何らかのパッケージをインストールする方法を紹介します。

インストール

ここでは、例としてmore-itertoolsをインストールします。

最初にキー入力の手間を省くため、インストール先のシンボリックリンクを作成します。

zsh
cd
ln -s Library/Application\ Support/Blender/4.3/scripts/addons

ls -H addonsでインストール済みのアドオンを確認できます。
今回の方法は、アドオンと同じ場所にパッケージをインストールします。

インストールは次のようにします。

zsh
pip3 install more-itertools -t addons

次のように確認してみましょう。

zsh
pip3 list --path addons
出力
Package        Version
-------------- -------
more-itertools 10.6.0

Blenderを起動して、Scriptingワークスペースで、import more_itertoolsでインポートできることを確認してみましょう。

アンインストール

アンインストールするには、次のようにフォルダを直接削除してください。

zsh
rm -r addons/more_itertools
rm -r addons/more_itertools-10.6.0.dist-info

なお、作業が終わったら、シンボリックリンクは削除してください。

zsh
rm addons

pip3についての補足

pip3は、macOSにプリインストールされているPython3.9用のものです。
BlenderのPythonとは別物ですが、今回は問題なく使えたので利用しています。

もし、BlenderのPythonのpipを利用したい場合は、pip3の代わりに下記を使ってください。

/Applications/Blender.app/Contents/Resources/4.3/python/bin/python3.11 -m pip

addonsフォルダを使う理由

BlenderのPythonでインポートできるパッケージの場所は、次のように確認できます。

BlenderのScriptingワークスペース
import sys
sys.path
出力(改行を追加)
[
    '/Applications/Blender.app/Contents/Resources/4.3/scripts/startup',
    '/Applications/Blender.app/Contents/Resources/4.3/scripts/modules',
    '/Applications/Blender.app/Contents/Resources/4.3/python/lib/python311.zip',
    '/Applications/Blender.app/Contents/Resources/4.3/python/lib/python3.11',
    '/Applications/Blender.app/Contents/Resources/4.3/python/lib/python3.11/lib-dynload',
    '/Applications/Blender.app/Contents/Resources/4.3/python/lib/python3.11/site-packages',
    '/Applications/Blender.app/Contents/Resources/4.3/scripts/freestyle/modules',
    '/Users/Your Name/Library/Application Support/Blender/4.3/scripts/addons/modules',
    '/Applications/Blender.app/Contents/Resources/4.3/scripts/addons_core',
    '/Users/Your Name/Library/Application Support/Blender/4.3/scripts/addons'
]

この中のどれかにインストールすれば使えることになります。
しかし、/Applications以下のフォルダはSIP(System Integrity Protection)で保護されているので、今回はユーザーのフォルダのaddonsを使いました。

単純にpip3 installすると、通常のインストール先(/Applications以下)にインストールできず、次の1行目のようにメッセージがでて、別の場所に正常にインストールされます。しかし、そのインストール先はsys.pathにないので、インストールしてもBlenderで使うことはできませんので、注意してください。

出力
Defaulting to user installation because normal site-packages is not writeable
Collecting more-itertools
...(中略)
Successfully installed more-itertools-10.6.0

以上

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?