1
$\begingroup$

Please read carefully

this is not about installing packages with Blender's python, but rather their reverse - ignoring system packages.

I DO NOT WANT Blender to use the packages in site-packages - and all those questions are about how you get to do it.

Also - see at bottom: it seems this started with Python 3.10 (Blender 3.1).


When I try to install packages with pip I installed under Blender, I get messages such as

Requirement already satisfied: svgpathtools in /home/simone/.local/lib/python3.10/site-packages (1.6.1)

However, Blender's python then doesn't find them when executing scripts.

How do I get Blender's pip to ignore system python's site_packages?

Right now I am working around this by renaming site_packages, but that's horrible and time consuming.

BTW, this seems new to Blender 3.4 (but no guarantee about that).

This is the command I use:

simone$ /home/simone/blender/blender-3.4.1-linux-x64/3.4/python/bin/pip install scikit-learn

and this the output I get:

Requirement already satisfied: scikit-learn in /home/simone/.local/lib/python3.10/site-packages (1.2.1)
Requirement already satisfied: numpy>=1.17.3 in /home/simone/.local/lib/python3.10/site-packages (from scikit-learn) (1.23.5)
Requirement already satisfied: scipy>=1.3.2 in /home/simone/.local/lib/python3.10/site-packages (from scikit-learn) (1.11.1)
Requirement already satisfied: joblib>=1.1.1 in /home/simone/.local/lib/python3.10/site-packages (from scikit-learn) (1.2.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/simone/.local/lib/python3.10/site-packages (from scikit-learn) (3.1.0)

and the same results come if I use

simone$ /home/simone/blender/blender-3.4.1-linux-x64/3.4/python/bin/python3.10 -m pip install scikit-learn

and this is the screenshot of my preferences:

enter image description here

with no trace of extra/strange paths being added in.

I've also recursively looked for the string site-packages in my .config/blender directory and found nothing suspicious - except in dream-textures, which I have since deleted - with no result.

Just for kicks, I run this script

 import sys
 for p in sys.path:
     print(p)

on all pythons in all my blender installs. This is the result:

/home/simone/blender/blender-2.93.14-linux-x64/2.93/python/bin/python3.9

/home/simone/blender/blender-2.93.14-linux-x64/2.93/python/lib/python3.9
/home/simone/blender/blender-2.93.14-linux-x64/2.93/python/lib/python3.9/lib-dynload
/home/simone/blender/blender-2.93.14-linux-x64/2.93/python/lib/python3.9/site-packages
/home/simone/blender/blender-2.93.14-linux-x64/2.93/python/lib/python39.zip

/home/simone/blender/blender-3.0.1-linux-x64/3.0/python/bin/python3.9

/home/simone/blender/blender-3.0.1-linux-x64/3.0/python/lib/python3.9
/home/simone/blender/blender-3.0.1-linux-x64/3.0/python/lib/python3.9/lib-dynload
/home/simone/blender/blender-3.0.1-linux-x64/3.0/python/lib/python3.9/site-packages
/home/simone/blender/blender-3.0.1-linux-x64/3.0/python/lib/python39.zip

/home/simone/blender/blender-3.1.2-linux-x64/3.1/python/bin/python3.10

/home/simone/.local/lib/python3.10/site-packages
/home/simone/blender/blender-3.1.2-linux-x64/3.1/python/lib/python3.10
/home/simone/blender/blender-3.1.2-linux-x64/3.1/python/lib/python3.10/lib-dynload
/home/simone/blender/blender-3.1.2-linux-x64/3.1/python/lib/python3.10/site-packages
/home/simone/blender/blender-3.1.2-linux-x64/3.1/python/lib/python310.zip

/home/simone/blender/blender-3.2.0-linux-x64/3.2/python/bin/python3.10

/home/simone/.local/lib/python3.10/site-packages
/home/simone/blender/blender-3.2.0-linux-x64/3.2/python/lib/python3.10
/home/simone/blender/blender-3.2.0-linux-x64/3.2/python/lib/python3.10/lib-dynload
/home/simone/blender/blender-3.2.0-linux-x64/3.2/python/lib/python3.10/site-packages
/home/simone/blender/blender-3.2.0-linux-x64/3.2/python/lib/python310.zip

/home/simone/blender/blender-3.4.1-linux-x64/3.4/python/bin/python3.10

/home/simone/.local/lib/python3.10/site-packages
/home/simone/blender/blender-3.4.1-linux-x64/3.4/python/lib/python3.10
/home/simone/blender/blender-3.4.1-linux-x64/3.4/python/lib/python3.10/lib-dynload
/home/simone/blender/blender-3.4.1-linux-x64/3.4/python/lib/python3.10/site-packages
/home/simone/blender/blender-3.4.1-linux-x64/3.4/python/lib/python310.zip

/home/simone/blender/blender-3.5.0-linux-x64/3.5/python/bin/python3.10

/home/simone/.local/lib/python3.10/site-packages
/home/simone/blender/blender-3.5.0-linux-x64/3.5/python/lib/python3.10
/home/simone/blender/blender-3.5.0-linux-x64/3.5/python/lib/python3.10/lib-dynload
/home/simone/blender/blender-3.5.0-linux-x64/3.5/python/lib/python3.10/site-packages
/home/simone/blender/blender-3.5.0-linux-x64/3.5/python/lib/python310.zip

So it seems like the lookup in my system Python starts with 3.1. What's going on? how can I stop that? Is there a config variable I messed up by mistake?

$\endgroup$
6
  • $\begingroup$ Hello, it might come from the way you compiled Blender. Did you use an official distribution ? $\endgroup$
    – Gorgious
    Commented Aug 16, 2023 at 15:33
  • $\begingroup$ @Gorgious - yes, official download $\endgroup$
    – simone
    Commented Aug 16, 2023 at 16:35
  • $\begingroup$ @HarryMcKenzie - I get an empty string $\endgroup$
    – simone
    Commented Aug 16, 2023 at 16:35
  • $\begingroup$ as a workaround could u try add this before u run pip within Text Editor. unwanted_paths = ['/home/simone/.local/lib/python3.10/site-packages'] sys.path = [p for p in sys.path if p not in unwanted_paths] in blender 3.1 for example $\endgroup$
    – Harry McKenzie
    Commented Aug 16, 2023 at 16:45
  • $\begingroup$ @HarryMcKenzie - thanks, but add to what? $\endgroup$
    – simone
    Commented Aug 16, 2023 at 16:49

1 Answer 1

1
$\begingroup$

I noticed you executed the command in a native Linux Console or Terminal:

simone$ /home/simone/blender/blender-3.4.1-linux-x64/3.4/python/bin/pip install scikit-learn

You have to be very careful of the subtle differences. You are executing the command within the Terminal which can affect where the packages are installed and whether Blender's Python environment can access them. So I think this is likely the reason you have messed up your environment with previous executions. You should have used the proper way to install Blender Python packages with the method outlined in this answer using the Text Editor in Blender to ensure that the package is installed and integrated properly within the context of Blender's Python environment.

enter image description here

For now as a temporary workaround you could exclude that unwanted path from sys.path before running any script that will try to get this path involved. Like for example if you want to install package scikit-learn, run the script like this:

import sys
import subprocess
import os

unwanted_paths = ['/home/simone/.local/lib/python3.10/site-packages']
sys.path = [p for p in sys.path if p not in unwanted_paths]
print(sys.path)
python_exe = os.path.join(sys.prefix, 'bin', 'python.exe')
subprocess.call([python_exe, '-m', 'pip', 'install', '--upgrade', 'scikit-learn'])

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .