Select your Python virtual environments directly from Sublime Text.
This is a plugin for Sublime Text that provides a simple way to select Python virtual environments directly from the editor. The plugin allows you to:
- List available virtual environments: Automatically detects virtual environments in specified directories.
- Activate a virtual environment: Updates the environment variables and adds the selected virtual environment to the
PATH
. - Deactivate the current virtual environment: Restores the system environment to its original state.
- Integration with LSP-pyright and LSP-basedpyright: Attempts to notify the LSP language server about the active virtual environment, enabling better Python language support.
- Quick Panel Selection: Use a quick panel to select and activate a virtual environment.
- Customizable Directories: Configure directories to search for virtual environments in the
Virtualenv Selector (PLATFORM).sublime-settings
file. - Automatic PATH Update: Updates the
PATH
environment variable to include the selected virtual environment. - Basic LSP-pyright Integration: Notifies LSP-pyright when the virtual environment changes, though full automatic integration with LSP-pyright is not yet functional.
- Sublime Text 4
- LSP-pyright or LSP-basedpyright (optional, for enhanced Python language support)
- Python installed on your system
- Clone this repository into your Sublime Text
Packages
directory:git clone https://github.com/<your-username>/<your-repo>.git "Virtualenv"
- Restart Sublime Text.
- Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
on macOS). - Run the command
Virtualenv Selector: Activate
. - Select a virtual environment from the list.
- Open the Command Palette.
- Run the command
Virtualenv Selector: Deactivate
.
- Open the
Virtualenv Selector (PLATFORM).sublime-settings
file:- From the Command Palette, run
Preferences: Virtualenv Selector Settings
.
- From the Command Palette, run
- Add or modify the
environment_directories
setting to include paths where your virtual environments are located. For example:{ "environment_directories": [ "~/.virtualenvs", "~/my_other_envs" ] }
- The automatic activation of Pyright and Basedpyright using the selected virtual environment is still under test. It should work just fine when working with Sublime Text projects.
Contributions are welcome! Feel free to open issues or submit pull requests to enhance functionality or fix bugs.
This plugin is licensed under the MIT License. See the LICENSE file for more details.
- Author: Andrea Alberti
- GitHub Profile: alberti42
- Donations:
Feel free to contribute to the development of this plugin or report any issues in the GitHub repository.