Closed4

Blender の addon で ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' が出るとき

nikogolinikogoli

現象

addon を有効化しようとすると、以下のようなエラーが出て失敗する

Traceback (most recent call last):
  File "C:\Users\~~~~~~\anaconda3\Lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "C:\Users\~~~~~~\anaconda3\Lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Users\~~~~~~\anaconda3\Lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\scripts\modules\addon_utils.py", line 333, in enable
    mod = __import__(module_name)
  File "C:\Users\~~~~~~\AppData\Roaming\Blender Foundation\Blender\3.3\scripts\addons\Blender-Scramble-Addon\__init__.py", line 114, in <module>
    from . import (
  File "C:\Users\~~~~~~\AppData\Roaming\Blender Foundation\Blender\3.3\scripts\addons\Blender-Scramble-Addon\DATA_PT_skeleton.py", line 10, in <module>
    import numpy as np
  File "C:\Users\~~~~~~\anaconda3\Lib\site-packages\numpy\__init__.py", line 150, in <module>
    from . import core
  File "C:\Users\~~~~~~\anaconda3\Lib\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\bin\python.EXE"
  * The NumPy version is: "1.21.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'
nikogolinikogoli

ググる色々出てくるが、一番問題の理解に役立ったのはこれ
https://devtalk.blender.org/t/solved-importerror-numpy-issues/9166

Usually means the numpy folder in blender’s local site-packages has been partially overwritten with a different version.

  • この記述を踏まえると、blender の site-packages にある numpy を読み込む必要がある
  • しかし、エラーメッセージでは、 anaconda の site-packages にある numpy を読み込んでいる

要するに:blender の site-packages の numpy を読み込めていないのが原因

nikogolinikogoli

対処法

モジュール検索パスに blender の site-packages を追加し、anaconda の パスよりも先に探索させる

具体的には

問題になっているファイルにおいて、.insert(0, path)を使ってモジュール検索パスの先頭に blender の site-packages を追加する

+ import sys
+ sys.path.insert(0, r"C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\site-packages")
  import numpy as np

読み込んだモジュールの中でもモジュール検索が行われる場合、変更が完全に反映されず、anaconda のパスが内部で使用され続けてエラーが消えないことがある。その場合は、blender を再起動する。

nikogolinikogoli

それでもエラーが出るとき

numpy の読み込みではなく numpy 自体に問題があるので、上のリンクにあるように、blender の python 経由で numpy を入れ直すしかないと思われる

このスクラップは2022/10/17にクローズされました