• Mac OSX 10.11.6
  • Blender 2.79
  • CellBlender 1.1
  • MCell 3.4

I recently installed Blender, CellBlender and Mcell as described here: http://mcell.org/tutorials/install_cellblender.html http://mcell.org/tutorials/install_mcell_linux_osx.html

I have been working my way through the tutorials (http://mcell.org/tutorials/) and had success with diffusion and unimolecular reaction simulations, but when I tried to plot the results of the unimolecular reaction simulation with the MatPlotLib Plotter (see http://mcell.org/tutorials/unimol_reactions.html), it does not produce a plot.

I suspect this may be an issue with the backend associated with whatever version of Python and Matplotlib that Blender/CellBlender is accessing.

Until now I have done all of my python/matplotlib work using a Macports installation of Python 2.7/matplotlib 2.1, but I don't think my Blender/CellBlender installation is touching the Macports installation since I did not install Blender through Macports.

So is Blender just using the system Python? How do I find out the version/location of Python and matplotlib that Blender/CellBlender is accessing? If the backend is indeed the problem, perhaps I can fix the problem by switching the backend in the appropriate matplotlibrc file?

The python interactive console in Blender tells me I am using Python version 3.5.3. It appears that there is no matplotlib available for Blender to use. For example, in the python interactive console I can find the version of numpy by typing

import numpy as np
print (np.__version__)

and I get 1.11.2 as an output. But if I try the same for matplotlib:

import matplotlib as mpl

I get the following output:

Traceback (most recent call last): File "<blender_console>", line 1, in <module> ImportError: No module named 'matplotlib'

So now my question is how to install matplotlib for use in Blender? As I mentioned above, I already have Python 2.7/matplotlib 2.1 installed through Macports, but that is apparently a sandboxed version that is not touched by Blender. Can I install a separate version of matplotlib that will only be used in Blender, and still use my Python 2.7/matplotlib 2.1 outside of Blender?


1 Answer 1


After a lot of digging and trial and error troubleshooting, I have resolved the issue myself. This answer is specifically for the OS and software/package versions specified in the original question.

Blender 2.79 comes with Python 3.5.3 and Numpy 1.11.2 bundled with it. Other Python packages (e.g. SciPy, matplotlib) are not bundled with Blender.

Install Python 3.5 using Macports, along with the appropriate matplotlib (and any other packages you want to add to Blender) then copy the desired packages from the Macports location to the Blender location.

You can keep python 2.7 as the default python for your system, and set python 3.5 as default for python3 commands:
sudo port select --set python python27
sudo port select --set python3 python35

For me the location of matplotlib in the Macports install is: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib

And the location that Blender accesses is: /Applications/Blender/blender.app/Contents/Resources/2.79/python/lib/python3.5/site-packages/

Note that the README file at this location states:

This directory exists so that 3rd party packages can be installed here. Read the source for site.py for more details.

(Confirming that we have the right location)

So, to copy Macports matplotlib package(s) to Blender:
cp -r /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib /Applications/Blender/blender.app/Contents/Resources/2.79/python/lib/python3.5/site-packages/

You will probably want to copy numpy over as well (replace the existing one bundled with Blender), because the matplotlib you just installed with Macports was compiled with a newer version of numpy (1.13.3) rather than what is bundled with Blender (1.11.2). Matplotlib won't play well with the older version of numpy.

There are some additional packages that Blender needs in order to use matplotlib:

These should be copied from and to the same locations specified above for matplotlib.

(See also this post by avocadohead: http://eumenidae.blogspot.com/2015/09/adding-matplotlib-to-locally-installed.html)

(You can take my word for it, or avocadohead's, or you can find these dependencies yourself by trying to plot from the python console in Blender - you will get an import error telling you what it can't find. Then just keep copying over what Blender said it was looking for until the import errors stop).

Note: if you ever update Blender, the above process must be repeated (unless a new version of Blender fixes the issue by bundling these packages)

But there is also an issue with the backend. Start Blender from the terminal so you can see what is going on behind the scenes (I recommend doing this from the beginning actually, because it provides answers a lot of the originally posted questions above regarding the versions and locations of python modules/packages used by Blender). When you try to plot something using the 'Plot' button in 'Plot Output Settings' in CellBlender, you will see the following error in the terminal:

RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

We can fix this by changing the backend. I recommend Qt4Agg. But Qt4Agg requires an additional module, either PyQt4 or PySide. Blender will only work with PySide. So install py35-pyside using Macports, and copy it over to the Blender location as described above for matplotlib and the other packages.

Now we just need to make this the default backend for matplotlib in Blender. This is done by editing the matplotlibrc file. For me, the Blender matplotlibrc file is found here: /Applications/Blender/blender.app/Contents/Resources/2.79/python/lib/python3.5/site-packages/matplotlib/mpl-data

Open it in your favorite editor and change backend from MacOSX to Qt4Agg then uncomment the line backend.qt4 : PyQt4 and change PyQt4 in that line to PySide.

Now, (finally) when you try to plot something using the 'Plot' button in 'Plot Output Settings' in CellBlender, you will get a plot (and it is in a separate window)!

Other useful posts that helped me get to the bottom of this: https://blenderartists.org/forum/showthread.php?304089-Install-Matplotlib-and-all-its-dependencies-to-use-within-Blender

Using 3rd party Python modules

Also, don't bother registering with mmbios.org with the intention of asking urgent questions on their forum - the administrator will take days (still counting) to activate your account, if they activate it at all.

  • $\begingroup$ Instead of copying, symlinking also works. So something like ln -s /usr/local/lib/python3.6/site-packages/dateutil/ /path/toblender/modules/dateutil (the python location assumes you are using brew instead of macports) $\endgroup$
    – rien333
    Mar 8, 2018 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .