I have a bunch of modules that I had previously installed using pip to my system python 2.7. What do I need to do in order to be able to import this module in the blender python console, as well as within my python scripts in blender? (The module in question is called ProDy).

EDIT: I installed pyenv and installed the same version of python as my blender version (3.5.3) uses through it. I then made this version active, and installed the packages I need with pip3 install. I can load the packages in terminal, but not in the blender python console. What am I missing?

  • $\begingroup$ You'll have to upgrade to Python 3 first. $\endgroup$ – dr. Sybren May 11 '18 at 6:49
  • $\begingroup$ So if I python 3 and the modules for python 3, that would work in blender? $\endgroup$ – sodiumnitrate May 11 '18 at 13:55
  • $\begingroup$ @dr.Sybren I tried this, please see the updates in the post. $\endgroup$ – sodiumnitrate May 11 '18 at 16:52
  • 1
    $\begingroup$ I answered a similar question not too long ago about installing scipy. The instructions should work for you too if you're using Windows. $\endgroup$ – doakey3 May 11 '18 at 16:56
  • $\begingroup$ @doakey3 Oh cool, thanks! I'm using mac, but I guess it should still be the same. One question though: would I have to do this every time I launch blender? $\endgroup$ – sodiumnitrate May 11 '18 at 16:58

For pip-installable dependencies (like PyPI or wheels), all you need to do is the following:

  1. Locate your Blender's Python binary path, let's call it <BPYTHON> (in my case 2.80/python/bin/python3.7m at the Blender installation).

  2. Run the following to enable pip operations in bpython:

<BPYTHON> -m ensurepip
<BPYTHON> -m pip install --upgrade pip
  1. Now any time you want to install a package simply call pip from bpython:
<BPYTHON> -m pip install <YOUR_PACKAGE>  # no --user needed
<BPYTHON> -m pip install <PATH/TO/WHEEL>.whl  # also works with wheels as expected

As usual, you just have to install a package once and uninstalling works the analogous way.

Blender's Python has its own environment, so this procedure will install the dependencies there (in my case the 2.80/python folder). AFAIK this will work irrespectively of your OS, system's Python version and Blender location so I found this to be most convenient. You can encounter some issues if installing cython-related packages like tkinter but this can also be fixed as I did here.

Let me know if this works out!

  • $\begingroup$ If you use pip install --user foo the modules will be available if using either system or bundled python of same version. $\endgroup$ – batFINGER May 12 '19 at 4:33
  • $\begingroup$ Cool! thanks for the info. How is that? I checked Blender's sys.path but didn't find any clear pointers $\endgroup$ – fr_andres May 13 '19 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.