UV Mode provides seamless integration between uv (the Python package installer) and Emacs python-mode. Unlike pyenv-mode which manages multiple Python versions, UV Mode focuses on managing project-specific virtual environments created by uv.
UV Mode automatically detects and activates virtual environments created by uv in your Python projects. When you open a Python file, UV Mode checks for a .venv
directory in the project root and activates it if found. This enables seamless switching between different Python projects, each with its own isolated environment.
Key features include:
- Automatic virtual environment detection and activation
- Mode line indicator showing the current project/environment
- Integration with pythonic.el for enhanced Python development
- Simple keybindings for manual control when needed
- Emacs 25.1 or later
- uv installed and available in your PATH
- pythonic.el package
(use-package uv-mode
:hook (python-mode . uv-mode-auto-activate-hook))
-
Clone this repository:
git clone https://github.com/z80/uv-mode.git
-
Add the following to your Emacs configuration:
(add-to-list 'load-path "/path/to/uv-mode") (require 'uv-mode) (add-hook 'python-mode-hook #'uv-mode-auto-activate-hook)
UV Mode works automatically once installed. Simply open a Python file in a project that has a .venv
directory, and UV Mode will activate the appropriate virtual environment.
While automatic activation is the primary way to use UV Mode, you can also control it manually:
C-c C-s
: Manually activate the virtual environment for the current projectC-c C-u
: Deactivate the current virtual environment
When active, UV Mode displays the current project name in the mode line with the prefix "UV:". This helps you quickly identify which virtual environment is active.
UV Mode expects your Python projects to follow this structure:
project-root/
├── .venv/ # UV-created virtual environment
├── src/
│ └── your_code.py
└── other_files
The .venv
directory should be created using uv. UV Mode will automatically detect this directory and use it as the project's virtual environment.
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
UV Mode was inspired by pyenv-mode and adapted to work with uv's project-local virtual environments approach.