You need modules that work with the same Python version as the one shipped with blender (currently, blender 2.78 is shipped with Python 3.6.0).
My favorite Python distribution is anaconda. Here are the steps I just followed for blender 2.78 in linux (a similar setup should be easy to get for windows or macos).
- Install anaconda.
- Create an specific environment for the modules you need in blender:
conda create --name conda-python-blender python=3.6.0
- Activate this environment:
source activate conda-python-blender
- Install all your required libraries ("modules"):
conda install cython
- You can also use
pip if your library is not (yet) in anaconda repositories:
pip install mdtraj
- Figure out the directory where your libraries are stored:
echo "import sys; print(sys.path)" | python
In my case, I get:
['', '/home/christophe/anaconda3/envs/conda-python-blender/lib/python36.zip', '/home/christophe/anaconda3/envs/conda-python-blender/lib/python3.6', '/home/christophe/anaconda3/envs/conda-python-blender/lib/python3.6/lib-dynload', '/home/christophe/anaconda3/envs/conda-python-blender/lib/python3.6/site-packages', '/home/christophe/anaconda3/envs/conda-python-blender/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg']
You want the "
site-packages" directory, so, in my case:
- Open blender, then go to the Python console and do the following as Rich Colburn said, that is adding the previous directory the the path where Python is looking for libraries:
And that's it!
- Optional step. If you want to make it permanent so that every time you open a new blender file, blender adds automatically the required directory to the path, then save the following lines in a file (say
add-anaconda-libs-to-path.py) and put the file in
./scripts/startup/ (for me it is
print("Added anaconda library to path")
A final note: unless you want to update your libraries with
conda, you don't have to activate the
conda-python-blender environment anymore as blender will use its own Python interpreter.