Revert "enhance: Prebuilt terminal venv found but Python executable missing P…" (#1062)

This commit is contained in:
Tong Chen 2026-01-24 00:08:56 +08:00 committed by GitHub
parent 3bb75a3dba
commit 8a0e759906
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 133 additions and 103 deletions

View file

@ -170,29 +170,39 @@ export function getPrebuiltVenvPath(): string | null {
}
/**
* Find Python executable in prebuilt Python directory
* Find Python executable in prebuilt Python directory for terminal venv
*/
export function findPrebuiltPythonExecutable(): string | null {
function findPythonForTerminalVenv(): string | null {
const prebuiltPythonDir = getPrebuiltPythonDir();
if (!prebuiltPythonDir) {
return null;
}
const isWindows = process.platform === 'win32';
const pythonName = isWindows ? 'python.exe' : 'python';
const binPath = isWindows ? '' : path.join('install', 'bin');
// Look for Python executable in the prebuilt directory
// UV stores Python in subdirectories like: cpython-3.10.19+.../install/bin/python
const possiblePaths: string[] = [];
// UV stores Python in cpython-* subdirectories
// First, try common direct paths
possiblePaths.push(
path.join(prebuiltPythonDir, 'install', 'bin', 'python'),
path.join(prebuiltPythonDir, 'install', 'python.exe'),
path.join(prebuiltPythonDir, 'bin', 'python'),
path.join(prebuiltPythonDir, 'python.exe'),
);
// Then, search in subdirectories (UV stores Python in versioned directories)
try {
const entries = fs.readdirSync(prebuiltPythonDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory() && entry.name.startsWith('cpython-')) {
const pythonPath = isWindows
? path.join(prebuiltPythonDir, entry.name, 'install', pythonName)
: path.join(prebuiltPythonDir, entry.name, binPath, pythonName);
if (fs.existsSync(pythonPath)) {
log.info(`[PROCESS] Found prebuilt Python executable: ${pythonPath}`);
return pythonPath;
if (fs.existsSync(prebuiltPythonDir)) {
const entries = fs.readdirSync(prebuiltPythonDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory() && entry.name.startsWith('cpython-')) {
const subDir = path.join(prebuiltPythonDir, entry.name);
possiblePaths.push(
path.join(subDir, 'install', 'bin', 'python'),
path.join(subDir, 'install', 'python.exe'),
path.join(subDir, 'bin', 'python'),
path.join(subDir, 'python.exe'),
);
}
}
}
@ -200,7 +210,12 @@ export function findPrebuiltPythonExecutable(): string | null {
log.warn('[PROCESS] Error searching for prebuilt Python:', error);
}
log.info('[PROCESS] Prebuilt Python directory found but executable not found');
for (const pythonPath of possiblePaths) {
if (fs.existsSync(pythonPath)) {
return pythonPath;
}
}
return null;
}
@ -226,13 +241,13 @@ export function getPrebuiltTerminalVenvPath(): string | null {
log.info(`Using prebuilt terminal venv: ${prebuiltTerminalVenvPath}`);
return prebuiltTerminalVenvPath;
} else {
// Try to fix the missing Python executable by creating a symlink to
// prebuilt Python
// Try to fix the missing Python executable by creating a symlink to prebuilt Python
log.warn(
`Prebuilt terminal venv found but Python executable missing at: ${pythonExePath}. ` +
`Attempting to fix...`
);
const prebuiltPython = findPrebuiltPythonExecutable();
const prebuiltPython = findPythonForTerminalVenv();
if (prebuiltPython && fs.existsSync(prebuiltPython)) {
try {
const binDir = isWindows