This is a plugin for Sublime Text that provides a simple and efficient way to manage 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.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: Activate Virtual Environment
. - Select a virtual environment from the list.
- Open the Command Palette.
- Run the command
Virtualenv: Deactivate Virtual Environment
.
- Open the
Virtualenv.sublime-settings
file:- From the Command Palette, run
Preferences: Virtualenv 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 using the selected virtual environment does not fully work yet. The LSP-pyright language server is notified, but it may not correctly switch environments.
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.