If you are doing Blender scripting, sometimes you might want to do something very specific that requires one or more third party modules that are not available by default. Let’s see how you can install Python modules in Blender.
There are a few methods to do it, I believe that the one I will describe, that uses pip, is the simplest one. What I am showing was tested on Blender 2.79 and Blender 2.80 beta. I am working on Windows, however the steps should be similar also on the other operating systems.
1. Locate Blender’s bundled Python
Blender ships with its own version of Python. It should be in the Blender’s folder under
/blender/2.xx/python/ . However, to be sure, in the Python console of Blender you can type:
import sys sys.exec_prefix
and you will have your answer.
As a side note, I will say that if you want you can force Blender to use another another Python that you have installed on your machine. To do so just remove the Blender folder that you have just located and Blender will fallback to use the system’s Python. However, I prefer to stick with Blender’s own version of Python, keeping things separated from other projects.
Run Power Shell as administrator and navigate to the Blender’s Python folder.
2. Install pip
Using Blender’s python (that should be in the bin folder) run the module ensure pip, like in the image below.
3. Install Python modules in Blender using pip
pip is now in ./python/scripts and we can now use it to install new modules in Blender. It is important to stress that you have to use THIS version of pip, not the one that might already be available on your computer as environment variable, otherwise the new packages will not be visible to Blender.
In the example below I used pip to install the scikit-image module for a new project that I am working on.
Test the installation from the command line with Blender’s bundled Python or directly from Blender’s Python console. If there are errors read them and try to act accordingly.
I wrote this article after making some research on Blender Stack Exchange, in particular:
Interested in Sverchok? Then check out Learning Sverchok, the free ebook by CodePlastic!