Installing Python packages with pip in Blender on Windows 10

We can install additional python module packages to Blender, which are not installed by default, with pip. However, if we use Windows 10, the python interpreter installs new packages not into the Blender installation directory, but into the personal user directory.

During installation, pip will show the following warning in the system console:

Defaulting to user installation because normal site-packages is not writeable

The packages will be installed, but into the directory:

c:\Users\_windows_user_name_\AppData\Roaming\Python\Python39\site-packages\

As a result, packages are installed but are not available inside Blender – they cannot be accessed from the Python console or Blender Text Editor using the “import” command.

We can solve the problem by hard-coding the directory where pip should install the required packages – the “site-packages” directory located inside the directory where Blender is installed.

Let’s define 2 variables – in the first, we will set the path to the executable Blender python.exe file, in the second – the path where the packages would be installed.

First, upgrade pip:

And install the required package, specifying the destination directory:

Full code:

Now, the packages will be installed correctly, in a directory inside Blender, and can be used in it.


*.blend файл with code for my Patreon subscribers

5 2 votes
Article Rating
Subscribe
Notify of
guest

6 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Ilya
Ilya
1 year ago

If I install package with this code without admin privileges, it write in console:
“PermissionError: [WinError 5] Отказано в доступе: ‘C:\\Program Files\\Blender Foundation\\Blender 3.3\\3.3\\python\\lib\\site-packages\\numpy\\array_api\\linalg.py'”

jdh
jdh
1 year ago

If you have installed a number of extra libraries via pip to a blender install, and you update blender, how do you advise ‘mirroring’ your installed packages for the latest install of blender? eg going from 3.3 up to 3.4

jdh
jdh
1 year ago
Reply to  Nikita

I did think about this. My first thought was ‘what if a package I copy over has been updated and gets overwritten with the old one. not sure whether this is possible or not. I’m trying to be careful about what a best practice might be.