Skip to content

Commit 41ca07d

Browse files
committed
use vswhere.exe for python to find MSVS install if other methods fail
1 parent 65d7c5a commit 41ca07d

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

setup.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ def determine_generator_args(cmake_version=None, windows_sdk_version=None):
189189
elif '\\Microsoft Visual Studio 14.0' in compiler.cc:
190190
vs_version = 14
191191
vs_year = 2015
192+
else:
193+
# Fallback: use vswhere.exe when distutils can't detect the VS version
194+
# (e.g. Python 3.8 distutils doesn't know about VS2026)
195+
import subprocess
196+
vswhere = os.path.join(
197+
os.environ.get('ProgramFiles(x86)', r'C:\Program Files (x86)'),
198+
'Microsoft Visual Studio', 'Installer', 'vswhere.exe')
199+
if os.path.exists(vswhere):
200+
result = subprocess.run(
201+
[vswhere, '-latest', '-property', 'installationVersion'],
202+
capture_output=True, text=True)
203+
if result.returncode == 0 and result.stdout.strip():
204+
major = int(result.stdout.strip().split('.')[0])
205+
# VS major version -> marketing year mapping
206+
major_to_year = {14: 2015, 15: 2017, 16: 2019, 17: 2022, 18: 2026}
207+
vs_version = major
208+
vs_year = major_to_year.get(major, 2022 + (major - 17) * 3)
192209
assert (vs_version and vs_year)
193210
except Exception:
194211
raise RuntimeError('No supported version of MSVC compiler could be found!')

0 commit comments

Comments
 (0)