Preface
This extension is a replacement for my previous extension (vscode-micromamba-env). The previous version relied on the ms-python-envs API (Environment Provider), which unfortunately suffers from several upstream issues. This new version takes a new standalone approach by directly managing environment variables and interacting with the shell, ensuring a reliable experience for Micromamba users.
A simple and efficient VS Code extension to discover, select, and activate your Micromamba environments.
- Discovery: Automatically reads your environments from
~/.conda/environments.txt. - Filtering: Separates environments into "Workspace" (local to your project) and "Root/Global" (in your Micromamba root prefix).
- Activation:
- Injects environment variables directly into the VS Code Integrated Terminal.
- Automatically updates the Python extension path (
python.defaultInterpreterPath). - Auto-configuration: Automatically disables
python.terminal.activateEnvironmentin your workspace to prevent conflicts with the standard Python extension. - Generates a
.envfile in your workspace root for other tools.
- Performance: Caches critical Micromamba configuration (
MAMBA_ROOT_PREFIX,MAMBA_EXE) by querying your shell only once per session.
- Open the Command Palette (
Ctrl+Shift+P/Cmd+Shift+P). - Run
Micromamba: Select Environment. - Choose your environment from the list.
- The status bar will update, and new terminals will use this environment.
You can customize the extension in your settings.json:
{
"micromamba-envs.micromambaBinary": "/path/to/micromamba",
"micromamba-envs.rootPrefix": "/home/user/micromamba",
"micromamba-envs.environmentsTxtPath": "/home/user/.conda/environments.txt"
}micromamba-envs.micromambaBinary: (Optional) Manually specify the micromamba executable. If left empty, the extension attempts to find it via your shell variables (MAMBA_EXE).micromamba-envs.rootPrefix: (Optional) Manually specify the root prefix to filter global environments. If empty, it is detected viaMAMBA_ROOT_PREFIX.micromamba-envs.environmentsTxtPath: (Optional) Path to the file listing your environments. Defaults to~/.conda/environments.txt.
This extension is designed to be friendly with version control systems like Git.
When you select an environment, the extension updates your workspace settings (.vscode/settings.json):
- Sets
python.defaultInterpreterPathto the selected environment. - Sets
python.terminal.activateEnvironmenttofalse(to avoid conflicts).
- Local Environments (e.g., inside your project folder): The extension uses relative paths with
${workspaceFolder}(e.g.,${workspaceFolder}/.conda/bin/python). This allows you to commit the.vscode/settings.jsonfile so your team automatically uses the correct environment setup. - Global Environments: The extension uses absolute paths. Be careful not to commit
.vscode/settings.jsonif you use a machine-specific global path.
To ensure seamless integration with C++ libraries (DLLs) and other tools, this extension generates a .env file at the root of your workspace containing all necessary environment variables.
.gitignore:
# .gitignore
.env- Micromamba must be installed.
- Your shell (Bash, Zsh, PowerShell) should be configured properly (e.g., via
micromamba shell init ...) so thatMAMBA_ROOT_PREFIXis accessible if you don't provide it in settings.
Contributions are welcome! Please feel free to open an issue to report a bug or suggest a feature. If you want to contribute code, please open a Pull Request.
To get started with development:
-
Clone the repository:
git clone https://github.com/symzn/vscode-micromamba-env-selector.git cd vscode-micromamba-env-selector -
Install dependencies:
npm install
-
Compile the code:
npm run compile
You can also run
npm run watchto automatically recompile on file changes. -
Launch in Debug Mode:
- Press
F5in VS Code to open a new "Extension Development Host" window with the extension running. - You can now test your changes in this new window.
- Press
-
Package creation
- Install packaging tool
vsce
npm install -g @vscode/vsce
- Build package
vsce package
- Install packaging tool
This project is licensed under the MIT License. See the LICENSE file for details.