Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #80: find correct python path for blender 2.92 and before #174

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pythonFiles/include/blender_vscode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import List

import bpy

Expand All @@ -11,7 +12,7 @@ class AddonInfo:
module_name: str


def startup(editor_address, addons_to_load: list[AddonInfo], allow_modify_external_python):
def startup(editor_address, addons_to_load: List[AddonInfo], allow_modify_external_python):
if bpy.app.version < (2, 80, 34):
handle_fatal_error("Please use a newer version of Blender")

Expand Down
5 changes: 4 additions & 1 deletion pythonFiles/include/blender_vscode/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import threading
from functools import partial
from .utils import run_in_main_thread
from .environment import blender_path, scripts_folder
from .environment import blender_path, scripts_folder, python_path

EDITOR_ADDRESS = None
OWN_SERVER_PORT = None
Expand Down Expand Up @@ -52,6 +52,9 @@ def start_debug_server():
while True:
port = get_random_port()
try:
# for < 2.92 support (debugpy has problems when using bpy.app.binary_path_python)
# https://github.com/microsoft/debugpy/issues/1330
debugpy.configure(python=str(python_path))
debugpy.listen(("localhost", port))
break
except OSError:
Expand Down
5 changes: 4 additions & 1 deletion pythonFiles/include/blender_vscode/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from pathlib import Path
import platform

python_path = Path(sys.executable)
# binary_path_python was removed in blender 2.92
# but it is the most reliable way of getting python path for older versions
# https://github.com/JacquesLucke/blender_vscode/issues/80
python_path = Path(getattr(bpy.app, "binary_path_python", sys.executable))
blender_path = Path(bpy.app.binary_path)
blender_directory = blender_path.parent

Expand Down
8 changes: 6 additions & 2 deletions pythonFiles/include/blender_vscode/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def ensure_package_is_installed(name):

def install_package(name):
target = get_package_install_directory()
subprocess.run([str(python_path), "-m", "pip", "install", name, "--target", target], cwd=cwd_for_subprocesses)
command = [str(python_path), "-m", "pip", "install", name, "--target", target]
print("Execute: ", " ".join(command))
subprocess.run(command, cwd=cwd_for_subprocesses)

if not module_can_be_imported(name):
handle_fatal_error(f"could not install {name}")
Expand All @@ -49,7 +51,9 @@ def install_package(name):
def install_pip():
# try ensurepip before get-pip.py
if module_can_be_imported("ensurepip"):
subprocess.run([str(python_path), "-m", "ensurepip", "--upgrade"], cwd=cwd_for_subprocesses)
command = [str(python_path), "-m", "ensurepip", "--upgrade"]
print("Execute: ", " ".join(command))
subprocess.run(command, cwd=cwd_for_subprocesses)
return
# pip can not necessarily be imported into Blender after this
get_pip_path = Path(__file__).parent / "external" / "get-pip.py"
Expand Down
5 changes: 3 additions & 2 deletions pythonFiles/include/blender_vscode/load_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import traceback
from pathlib import Path
from typing import List

import bpy

Expand All @@ -11,7 +12,7 @@
from .utils import is_addon_legacy


def setup_addon_links(addons_to_load: list[AddonInfo]):
def setup_addon_links(addons_to_load: List[AddonInfo]):

path_mappings = []

Expand Down Expand Up @@ -44,7 +45,7 @@ def get_user_addon_directory(source_path: Path):
return Path(bpy.utils.user_resource("EXTENSIONS", path="user_default"))


def load(addons_to_load: list[AddonInfo]):
def load(addons_to_load: List[AddonInfo]):
for addon_info in addons_to_load:
if is_addon_legacy(Path(addon_info.load_dir)):
bpy.ops.preferences.addon_refresh()
Expand Down