Install Python module for Blender I'd like to install some python modules which need to be compiled and use them in Blender. Usually I'd pip install them but that doesn't seem to be a possibility for Blender. I tried copying sys.path from my system python environment but it came up with quite a few errors.

The modules are cython and mdtraj - both are available using anaconda and pip but both need to be compiled for the python environment they're supposed to be run on.

So how should I go about installing/setting those up for use in Blender?
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:



/home/christophe/anaconda3/envs/conda-python-blender/lib/python3.6/site-packages





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:




  import sys
  sys.path.append('/home/christophe/anaconda3/envs/conda-python-blender/lib/python3.6/site-packages')




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 /home/christophe/.config/blender/2.78/scripts/startup/.




import sys
sys.path.append('/home/christophe/anaconda3/envs/conda-python-blender/lib/python3.6/site-packages')
def register():
    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.