Skip to content

Commit

Permalink
Ensure correct python executable path for Blender 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
SBCV committed Jan 16, 2022
1 parent d964ef0 commit 39d0ae2
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions photogrammetry_importer/preferences/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@ def _get_addon_name():
return __name__.split(".")[0]


def _get_python_exe_path():
# https://developer.blender.org/rB6527a14cd2ceaaf529beae522ca594bb250b56c9
try:
# For Blender 2.80, ..., etc
python_exe_fp = bpy.app.binary_path_python
except AttributeError:
# For Blender 2.92, ..., etc
python_exe_fp = sys.executable
return python_exe_fp


def get_additional_command_line_sys_path():
"""Function that retrieves additional sys.path of the command line"""
script_str = "import sys; import json; pickled_str = json.dumps(sys.path); print(pickled_str)"
result = subprocess.run(
[sys.executable, "-c", script_str],
[_get_python_exe_path(), "-c", script_str],
stdout=PIPE,
stderr=PIPE,
)
Expand Down Expand Up @@ -56,7 +67,7 @@ def remove_command_line_sys_path():
additional_system_paths = json.loads(prefs.sys_path_list_str)
for additional_sys_path in additional_system_paths:
sys.path.remove(additional_sys_path)
prefs.sys_path_list_str = "[]"
prefs.sys_path_list_str = "[]"


@persistent
Expand Down Expand Up @@ -185,16 +196,6 @@ def get_package_info(self):
class OptionalDependency(DependencyStatus):
"""Class that describes an optional Python dependency of the addon."""

def _get_python_exe_path(self):
# https://developer.blender.org/rB6527a14cd2ceaaf529beae522ca594bb250b56c9
try:
# For Blender 2.80, ..., etc
python_exe_fp = bpy.app.binary_path_python
except AttributeError:
# For Blender 2.92, ..., etc
python_exe_fp = sys.executable
return python_exe_fp

def install(self, op=None):
"""Install this dependency."""
pip_manager = PipManager.get_singleton()
Expand All @@ -203,7 +204,7 @@ def install(self, op=None):
# https://pip.pypa.io/en/latest/cli/pip_install/#install-user
# The "--user" option does not work with Blender's Python version.
dependency_install_command = [
self._get_python_exe_path(),
_get_python_exe_path(),
"-m",
"pip",
"install",
Expand Down Expand Up @@ -242,7 +243,7 @@ def uninstall(self, op=None):
pip_manager = PipManager.get_singleton()
pip_manager.install_pip(lazy=True, op=op)
dependency_uninstall_command = [
self._get_python_exe_path(),
_get_python_exe_path(),
"-m",
"pip",
"uninstall",
Expand Down

0 comments on commit 39d0ae2

Please sign in to comment.