Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/resources/blender-scripts/install_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import bpy
import sys
import addon_utils
from pathlib import Path
import site
Comment on lines +35 to +36
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from pathlib import Path
import site

not required anymore


# install pip

Expand All @@ -44,6 +46,13 @@ def get_python_path():
path = sys.executable
return os.path.abspath(path)

def get_target_flags():
# On Windows pip will sometimes install dependencies to the wrong folder when not setting the target flag.
# See: https://github.com/mastodon-sc/mastodon-blender-view/pull/36
for path in site.getsitepackages():
if "site-packages" in path:
return ["--target", path]
return []
Comment on lines +49 to +55
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_target_flags():
# On Windows pip will sometimes install dependencies to the wrong folder when not setting the target flag.
# See: https://github.com/mastodon-sc/mastodon-blender-view/pull/36
for path in site.getsitepackages():
if "site-packages" in path:
return ["--target", path]
return []

not required


os.environ.pop("PIP_REQ_TRACKER", None)
ensurepip.bootstrap()
Expand All @@ -52,8 +61,10 @@ def get_python_path():
# install dependencies

python_path = get_python_path()
packages = {'grpcio', 'bidict', 'grpcio-tools', 'pandas'}
subprocess.check_output([python_path, '-m', 'pip', 'install', *packages])
target_flags = get_target_flags()

packages = ['grpcio', 'bidict', 'grpcio-tools', 'pandas']
subprocess.check_output([python_path, '-m', 'pip', 'install', *target_flags, *packages])
Comment on lines +64 to +67
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_flags = get_target_flags()
packages = ['grpcio', 'bidict', 'grpcio-tools', 'pandas']
subprocess.check_output([python_path, '-m', 'pip', 'install', *target_flags, *packages])
env = dict(os.environ)
env["PYTHONNOUSERSITE"] = "1"
packages = {'grpcio', 'bidict', 'grpcio-tools', 'pandas'}
subprocess.check_call([python_path, '-m', 'pip', 'install', *packages], env=env)

We don't need to provide a --target flag. Passing a PYTHONNOUSERSITE is apparently the preferred solution, as demonstrated her https://github.com/robertguetzkow/blender-python-examples/blob/92214a9d74eedad8572e890a374d5204623c796a/add_ons/install_dependencies/install_dependencies.py#L114-L117


# test if dependencies are installed

Expand Down