Get Blender to work running a Python environment other than the default one

Hi there, first time posting here. I am relatively new to Blender and I am using a Python-based tool to automatically generate some blender simulations. Everything works fine until I try to use some of the functions on my tool to dynamically change the dynamics on Blender as the frames go by (imagine that gravity changes due to changes in position, for example).

When I try to unpickle some variables I would like to transfer (which contain objects of classes with imports on their methods), I get the following error:

ImportError: cannot import name ‘_ccallback_c’ from 'scipy.lib’ (C:/Users/pythonEnv/Lib/site-packages\

This makes me think that Blender has found the site-packages I want it to use (on “pythonEnv”) but that it is not running with the python installation corresponding to those libs but with its own (the one you can find at “$PATH_BLENDER$/2.91/python/bin”). In fact, when I check for a sys.path.executable, it points to Blender’s python installation.

My intuition tells me that if I could run blender supported by this pythonEnv, the error would disappear since the data I want to unpickle exists without problem inside that environment.

Any suggestions or ideas?

Thank you very much!

TLDR: Can I run Blender with a python distribution other than the installed by default within Blender?

You can go to Blender’s pip (notice the dot for local dir in front) and do the install there.

D:\programs\graphics\blender29\2.91\python\Scripts>.\pip install scipy
Collecting scipy
  Downloading scipy-1.6.0-cp37-cp37m-win_amd64.whl (32.5 MB)
     |████████████████████████████████| 32.5 MB 6.4 MB/s
Requirement already satisfied: numpy>=1.16.5 in d:\programs\graphics\b

Then you try it

>>> from scipy.stats import norm
>>> norm.cdf(0)
  • There is also another way to install pip on the fly import pip just in case you want to automate this bit.
  • If you see in Blender’s terminal window PYTHON INTERACTIVE CONSOLE 3.7.7 it means that you must install this exact version to allow Blender to detect it. You will end up getting more confused about managing multiple python installations that way. Just using Blender’s pip is the best way because it makes also your addon easier to share.

Scipy was already installed. However, this is not an answer to my question. In particular, I am looking for a general method to make blender use a different Python environment, not just make scipy work.

Thanks anyway for the answer!

I think that this is related to how the Python interpreter integrates with Blender … implementing the bpy object and so on.

I managed to get it to run, although I am not entirely sure what the correct steps are. Apparently, I had 2 versions of scipy and it was trying to import from the wrong one.

After very light testing, it seems to work for me, but I wouldn’t just claim that it is 100% resolved with the amount of testing I put into it.

Thank you all anyway!

You can try this when you are in doubt about python versions:

For specific modules.

>>> import scipy
>>> scipy.__file__

For Python standard library (eventually means which Python you’re running on).

>>> import os
>>> os.path
<module 'ntpath' from 'D:\\programs\\graphics\\blender29\\2.91\\python\\lib\\'>

Also having in mind there are no customization on the sys.path, which means that you can import anything from anywhere this way. (Also this counts for environment variables, which are sneaky and alter your sys.path).

>>> import sys
>>> sys.path