fix: use site to get site-packages

This commit is contained in:
2026-07-06 22:40:50 +08:00
parent c275f8cb7e
commit 86e0f30e58
2 changed files with 17 additions and 8 deletions
+7 -4
View File
@@ -169,12 +169,15 @@ class DeployConfig(ConfigModel):
@cached_property @cached_property
def python(self) -> str: def python(self) -> str:
exe = self.filepath(self.PythonExecutable) # No need to read PythonExecutable
if os.path.exists(exe): # since you run this code with python, current python is the python
return exe
# exe = self.filepath(self.PythonExecutable)
# if os.path.exists(exe):
# return exe
current = sys.executable.replace("\\", "/") current = sys.executable.replace("\\", "/")
logger.warning(f'PythonExecutable: {exe} does not exist, use current python instead: {current}') # logger.warning(f'PythonExecutable: {exe} does not exist, use current python instead: {current}')
return current return current
@cached_property @cached_property
+10 -4
View File
@@ -5,7 +5,7 @@ from dataclasses import dataclass
from urllib.parse import urlparse from urllib.parse import urlparse
from deploy.Windows.config import DeployConfig from deploy.Windows.config import DeployConfig
from deploy.Windows.logger import logger, Progress from deploy.Windows.logger import Progress, logger
from deploy.Windows.utils import cached_property from deploy.Windows.utils import cached_property
@@ -46,9 +46,15 @@ class PipManager(DeployConfig):
return f'"{self.python}" -m pip' return f'"{self.python}" -m pip'
@cached_property @cached_property
def python_site_packages(self): def python_site_packages(self) -> str:
return os.path.abspath(os.path.join(self.python, '../Lib/site-packages')) \ import site
.replace(r"\\", "/").replace("\\", "/") paths = site.getsitepackages()
# site-packages should be site-packages folder
for path in paths:
if path.endswith('site-packages'):
return path
# Otherwise pick first
return paths[0]
@cached_property @cached_property
def set_installed_dependency(self) -> t.Set[DataDependency]: def set_installed_dependency(self) -> t.Set[DataDependency]: