CAD_Sketcher icon indicating copy to clipboard operation
CAD_Sketcher copied to clipboard

[BUG] Cad-Sketcher dependency install process might install to user site-packages instead of blender - missing PYTHONUSERSITE in install scripts.

Open laundmo opened this issue 2 years ago • 4 comments

Contact Details

laundmo#7544 on discord

Description

When installing the py-slvs package from within the addon, the wrong pip will be called.

Explanation of why this might happen, and correct code to install dependencies: https://github.com/robertguetzkow/blender-python-examples/tree/master/add_ons/install_dependencies#installing-the-package

The simple fix to this is to modify the environment variables with which pip commands are run.

This blender console script shows the issue:

>>> import sys
>>> sys.executable
'C:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\python\\bin\\python.EXE'

>>> import subprocess
>>> subprocess.check_output([sys.executable, "-m", "pip", "-V"])
b'pip 22.2 from C:\\Users\\laundmo\\AppData\\Roaming\\Python\\Python310\\site-packages\\pip (python 3.10)\r\r\n'

as you can see, this found the wrong pip (from my appdata site-packages)

heres a minimal version of the fix in action:

>>> import os
>>> environ_copy = dict(os.environ)
>>> environ_copy["PYTHONNOUSERSITE"] = "1"
>>> subprocess.check_output([sys.executable, "-m", "pip", "-V"], env=environ_copy)
b'pip 21.2.4 from C:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\python\\lib\\site-packages\\pip (python 3.10)\r\r\n'

Addon Version

latest

Blender Version

all

What platform are you running on?

Windows

laundmo avatar Aug 09 '22 19:08 laundmo

I'm open to making a PR for this myself over the next weekend - i'd just like a go-ahead first.

laundmo avatar Aug 09 '22 19:08 laundmo

oh wow, good catch, that could also explain some "breakages" for people with multiple blender versions and so on...

Anywhere the PYPATH variable is used in the codebase would be affected.

amrsoll avatar Aug 09 '22 20:08 amrsoll

Aye, stumbled across this on the Discord server where a user was having issues with the install proceess using condas pip which doesn't work at all outside of a conda environment. Its potentially huge to the install process breaking.

laundmo avatar Aug 09 '22 20:08 laundmo

If you could submit a PR that would be great obviously.

hlorus avatar Aug 09 '22 21:08 hlorus