Hello everybody! I’m going to show you how to install Python modules into Blender’s version of python. In data science it’s common to use modules such as Numpy and Pandas (if you're using Python), and whilst you could open up a separate Python interpreter or Jupyter notebook to use these modules it’s often nice to have all the tools that you need available in the one program.
This tutorial assumes that you are working on a Windows PC. I have tested this on Windows 8/10 on Blender 2.81a. I also used the Command Shell but Powershell might also work, if you prefer that. You will also require an internet connection.
Part 1: Find your Blender Python Folder
If you don’t know your Blender Python folder path you can open Blender and run the following in the Python Console (within Blender):
- import sys
- sys.exec_prefix
You may want to copy this into Notepad because you may not be able to copy the path straight into the Command Prompt.
Part 2: Run 'CMD' as admin
- Search ‘cmd’ in your Windows OS installation.
- Right click on ‘Command Prompt’ and select ‘Run as Administrator’.
- If a prompt appears, select ‘OK’ or ‘yes’.
Part 3: Run the following lines of code in the 'CMD'
Use the following to navigate to your python folder:
- cd ‘...\Blender\2.81\python’
This next step might fail if it does, continue to the next line, you might not need to run this.
- .\bin\python.exe -m ensurepip
The line below upgrades pip, setuptools and wheel to the latest version.
- .\bin\python.exe -m pip install --upgrade pip setuptools wheel
This next step installs opencv
- .\bin\python.exe -m pip install opencv-python --user
Now you can install modules! In this example we’ll install Numpy and Pandas but you can use this method to install other Python modules into Blender. The code examples are below:
- .\Scripts\pip3.exe install numpy
- .\Scripts\pip3.exe install pandas
If all goes well then you should be able to import Numpy and Pandas into Blender’s installation of Python and use them as I have in the image below. You can use the following lines to test your own installation. If you have Blender already open you may have to restart it.
Congrats! You now know how to install modules into Python in Blender. If there are other modules you’d like to install, navigate to the Blender python folder and run the .\Scripts\pip3.exe install line with the name of the module you wish to install.
If you have any questions or feedback please email me at: steambeanblog@gmail.com
Take care and stay safe!
- Kit