Skip to content

PyEnv: Windows path calculation bug causes environment grouping to fail #1180

@karthiknadig

Description

@karthiknadig

Problem

In pyenvUtils.ts, the calculation of versionsPath and envsPaths is incorrect on Windows due to the pyenv-win directory structure.

Current Code

// pyenvUtils.ts L128-130
const versionsPath = normalizePath(path.join(path.dirname(path.dirname(pyenv)), 'versions'));
const envsPaths = normalizePath(path.join(path.dirname(versionsPath), 'envs'));

Issue

On Windows, pyenv is located at ~/.pyenv/pyenv-win/bin/pyenv.bat. The current logic calculates:

  • path.dirname(path.dirname(pyenv))~/.pyenv/pyenv-win
  • Should be ~/.pyenv to find versions folder properly

This causes:

  1. Environment grouping (PYENV_VERSIONS vs PYENV_ENVIRONMENTS) to fail
  2. Environments not being associated with the correct manager

PET Server Reference

The PET server handles this correctly with platform-specific code in pet-pyenv/src/environment_locations.rs:

#[cfg(windows)]
pub fn get_home_pyenv_dir(env_vars: &EnvVariables) -> Option<PathBuf> {
    let home = env_vars.home.clone()?;
    Some(norm_case(home.join(".pyenv").join("pyenv-win")))
}

Suggested Fix

Add Windows-specific handling when calculating the versions and envs paths:

const pyenvDir = isWindows() 
    ? path.dirname(path.dirname(path.dirname(pyenv))) // Go up 3 levels on Windows
    : path.dirname(path.dirname(pyenv));
const versionsPath = normalizePath(path.join(pyenvDir, 'versions'));

Affected File

src/managers/pyenv/pyenvUtils.ts

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions