I'm using the embedded python in Blender, which doesn't have matplotlib installed. I want to add it dynamically, to load it from my anaconda python installation. For that I inserted the anaconda site-packages to the beginning of the sys.path:
sys.path.insert(1, '/.../anaconda3/lib/python3.5/site-packages')
And I successfully imported matplotlib. But when I tried to import matplotlib.pyplot, I got this error:
File ".../anaconda3/lib/python3.5/site-packages/matplotlib/_path.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
ImportError: numpy.core.multiarray failed to import
So I tried step by step to import numpy.core.multiarray. First, I imported numpy and numpy.core and both where from anaconda3 path.But when trying to import numpy.core.multiarray, it was imported from Blender's path! I even tried to remove the Blender's site-packages from the sys.path, but it didn't help.
EDIT
I think the problem is with imp.load_dynamic. The problem with numpy.core.multiarray was fixed when I called
imp.load_dynamic('numpy.core.multiarray', '.../anaconda3/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so')
Now I have a problem with _csv and libz... Something is telling me this isn't the best approach...
EDIT 2
I ended up installing matplotlib in Blender's enviroment using pip. It was a mess. If you are interested, these are the steps I needed to do.
matplotlib
has a number of C extensions that expect to link against the versions ofnumpy
and Python they were compiled with (i.e. you need ABI compatibility, not just API compatibility). You may be able to get things to work, but it's going to be fragile. Why not install matplotlib in Blender's embedded python environment?