A lightweight C command-line tool to discover and activate Python virtual environments.
activate scans a directory tree, identifies possible Python environments, and helps the user activate the selected environment from the current shell.
- Recursively scans directories looking for Python virtual environments
- Detects environments using a simple heuristic:
- presence of a
bin/directory - presence of
bin/activate - presence of a Python executable
- presence of a
- Supports multiple environments in the same project tree
- Automatically activates a single detected environment
- Interactive selection when multiple environments are found
- Lightweight C implementation with no external dependencies
- Current version supprorts only linux/MacOS
- The project is currently under development so bugs are expected
activate
├── include
│ ├── activate.h
│ ├── dir_list.h
│ ├── io.h
│ └── scan.h
│
├── src
│ ├── main.c
│ ├── activate.c
│ ├── dir_list.c
│ ├── scan.c
│ └── io.c
│
├── scripts
│ └── activate
│
├── Makefile
└── README.md
Requirements:
- GCC or another C compiler
- POSIX-compatible system
Build:
makeThe generated binary is:
activate-cli
Install for the current user:
make install PREFIX=$HOME/.localThis installs:
~/.local/bin/activate-cli
~/.local/bin/activate
Make sure ~/.local/bin is in your PATH:
export PATH="$HOME/.local/bin:$PATH"Add this 3 lines in the ~/.bashrc and you are ready to go
activate() {
source "$HOME/.local/bin/activate" "$@"
}activateThe current directory is used as the search root.
activate /path/to/projectExample:
project/
├── env/
│ └── bin/
│ ├── activate
│ └── python
│
└── experiments/
└── .venv/
└── bin/
├── activate
└── python
The tool detects both environments.
When multiple environments are found:
Multiple environments found:
1) /home/user/project/env/bin/activate
2) /home/user/project/experiments/.venv/bin/activate
Select environment:
The selected environment is sourced into the current shell.
Currently an environment is considered valid if:
environment/
└── bin/
├── activate
└── python
- Better error handling
- Cache discovered environments
- Environment names instead of full paths
- Shell completion
- Support for zsh/fish
- Package distribution