Skip to content

Commit 337c351

Browse files
committed
Small hotfix for venvs
1 parent f99f61d commit 337c351

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hatch_cpp/toolchains/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55
from re import match
66
from shutil import which
7-
from sys import executable, platform as sys_platform
7+
from sys import base_exec_prefix, exec_prefix, executable, platform as sys_platform
88
from sysconfig import get_config_var, get_path
99
from typing import Any, List, Literal, Optional
1010

@@ -369,10 +369,14 @@ def get_link_flags(self, library: HatchCppLibrary, build_type: BuildType = "rele
369369
flags += f" /Fe:{library.get_qualified_name(self.platform)}"
370370
flags += " /link /DLL"
371371
# Add Python libs directory - check multiple possible locations
372+
# In virtual environments, sys.executable is in the venv, but pythonXX.lib
373+
# lives under the base Python installation's 'libs' directory.
372374
python_libs_paths = [
373375
Path(executable).parent / "libs", # Standard Python install
374376
Path(executable).parent.parent / "libs", # Some virtualenv layouts
375377
Path(get_config_var("installed_base") or "") / "libs", # sysconfig approach
378+
Path(exec_prefix) / "libs", # exec_prefix approach
379+
Path(base_exec_prefix) / "libs", # base_exec_prefix approach
376380
]
377381
for libs_path in python_libs_paths:
378382
if libs_path.exists():

0 commit comments

Comments
 (0)