How to install required packages to the Blender Python with pip

For add-ons development, sometimes it is necessary to use packages that are not included in the core set of the Blender Python interpreter. Most often, the dependencies you need are included in the Python Package Index (PyPI) and can be installed to Blender through the Pip package management system.

For Windows 10 see the updated version of this article.

The Pip Package Manager is already installed in Blender. However, Blender does not allow us to install the desired packages in a common way with the “pip install package_name” command.

To install the necessary package to Blender using Pip, we need to perform the following:

Start Blender, open the “Text Editor” window and press the “New” button to create a new script.

First, we need to get the full path to the python.exe executable for the current Blender Python interpreter.

Let’s perform all the next actions in a subprocess not to slow down the Blender itself.

At first, it is always recommended to check the installation of the pip module and update it to the latest version.

After pip is updated we can install the necessary dependencies.

The following command will install the desired package to the Blender Python. Replace the “package_name” with the name of the desired package.

The final code:

After executing the script by clicking the “Run Script” button, the specified package will be installed to the Blender Python interpreter.

Note that for correct installation, active Internet access is required. You may also need to run Blender with administrator privileges.

3.9 7 votes
Article Rating
Subscribe
Notify of
guest

5 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Ben
Ben
2 years ago

Hello all !
Just a quick tip if you run into this kind of issue :

Your Blender python script won’t install the lib because it finds it inside your ‘python user’ (meaning your default OS python) site-packages, so when you import it inside your Blender script, you have an error.

1) Try uninstalling your ‘python user’ lib corresponding to the one you want to install inside blender.
2) Run your Blender script to install desired module for Blender’s python
3) Go back to your ‘python user’ and re-install the uninstalled libs from step 1.

Nick
Nick
2 years ago
Reply to  Ben

Or you can copy the package that’s already installed from the OS python instead (in my case, “C:\Users\[username]\AppData\Roaming\Python\Python39\site-packages”) into Blender’s site-packages (in my case, “C:\Program Files\Blender Foundation\Blender 2.93\2.93\python\lib\site-packages”). I did this for opencv-python and it works fine.

Marco
3 years ago

Thank you! This also works for older versions, such as Blender 2.79 (latest).

Last edited 3 years ago by Marco