I'm using MacOS Catalina and I following this question to install scipy with my addon: How to write my add-on so that when installed it also installs dependencies (let's say: scipy or numpy-quaternion)?

Running this code downloads and installs the module so I can use it in Terminal:

>>> import scipy
>>> print(scipy.pi)

However Blender doesn't see the module:

Traceback (most recent call last):
  File "/Text", line 2, in <module>
ModuleNotFoundError: No module named 'scipy'
Error: Python script failed, check the message in the system console

What I noticed is that if I try to run the install code again, I see this in the console:

Requirement already up-to-date: pip in /Applications/Blender.app/Contents/Resources/2.83/python/lib/python3.7/site-packages (20.1.1)
Requirement already satisfied: scipy in ./.local/lib/python3.7/site-packages (1.4.1)
Requirement already satisfied: numpy>=1.13.3 in /Applications/Blender.app/Contents/Resources/2.83/python/lib/python3.7/site-packages (from scipy) (1.17.0)

So scipy is located in ./.local and other modules are in Blender.app/Contents/. Does anyone know how can I fix this and use scipy in my addon?

  • $\begingroup$ Use bpy.app.binary_path_python to get the path to Blender's Python as shown here. $\endgroup$ – Robert Gützkow May 22 '20 at 20:09
  • $\begingroup$ @RobertGützkow thank you for your reply. Unfortunately it's not: when I use your example to install a module I don't have (matplotlib you had there) it works, when I changed it to scipy I got the same warning as before: Requirement already satisfied + failed to import the module imgur.com/a/pbA4FC2 $\endgroup$ – Sergey Kritskiy May 23 '20 at 5:52
  • $\begingroup$ @RobertGützkow ok so I manually uninstalled scipy that I had before, reinstalled it from your addon and it works now, thank you! Do you have any idea what has happened? I checked and bpy.app.binary_path_python was the same path that I used in my script (str(py_exec)). Was it because something about using a wrong pip..? $\endgroup$ – Sergey Kritskiy May 23 '20 at 5:59
  • $\begingroup$ You don't have to use the --user flag. There are some improvements planned that would allow this to work properly, but they are not implemented yet (see developer.blender.org/T71420) $\endgroup$ – Robert Gützkow May 23 '20 at 7:43
  • $\begingroup$ You would have to add the modules to your sys.path if your using --user. $\endgroup$ – Robert Gützkow May 23 '20 at 16:40

Browse other questions tagged or ask your own question.