Virtual environments
These steps will help you list all the virtual environment management tools available on your Kali system.
Check System-Wide Package Managers for Installed Tools:
Python vs. pyenv
We may have two different Python environments on the system:
-
System Python (Managed by
update-alternatives
)- Installed globally in
/usr/bin/python
,/usr/bin/python3.x
- Used by system packages (like APT, scripts in
/usr/bin
, or Kali dependencies) - Controlled via
update-alternatives
- Can be Python 3.11 (or any other preferred default)
- Installed globally in
-
pyenv Python (User-Managed)
- Installs Python versions under
~/.pyenv/versions/
- Allows switching between multiple Python versions per project or globally
- Uses shims (
~/.pyenv/shims/
) to redirectpython
to the right version - Overrides system Python when active
- Installs Python versions under
How They Coexist
- When pyenv is inactive, the system uses the Python version set by
update-alternatives
(e.g.,/usr/bin/python3.11
). - When pyenv is active, it intercepts the
python
command and runs its own managed Python versions from~/.pyenv/versions/
. - Pyenv does NOT modify or replace system Python—it just redirects the
python
command using a shim.
How to Make Them Work Together
1. Set Python 3.11 as System Default (For System-Wide Use)
This makes sure that, when pyenv is NOT active, Python 3.11 is used.
2. Make Sure Pyenv Works Properly
Make sure pyenv is correctly installed in your shell:
To persist these settings, add them to ~/.zshrc
or ~/.bashrc
:
Now, when you activate pyenv, it will take control over Python.
3. Switching Between System Python and Pyenv
Use System Python (Python 3.11 from update-alternatives
). To temporarily disable pyenv and use system Python:
Use a Pyenv-Managed Python Version To switch to a specific pyenv-managed Python version:
4. To use a project-specific version:
virtualenvwrapper
Installation
Basic usage
Backing up virtual environment before removing it:
venv
Now you can activate or deactivate the virtual environment with:
pyenv
Install prerequisites: Ensure you have the required dependencies for pyenv
installation.
Install pyenv
: Use the following commands to install pyenv
:
Update .bashrc to set up pyenv: Add the following to your .bashrc (or .zshrc if using zsh):
Then, reload your shell configuration:
This command installs Python 2.7.18, or you can choose another Python 2.7 version if needed.
Create a Python 2.7 virtual environment: Once Python 2.7 is installed, you can create a virtual environment with:
Activate the virtual environment: To activate the environment, run:
Or deactivate:
1. Install and Configure pyenv
Ensure pyenv
is installed and properly configured.
1.1 Install pyenv (If Not Already Installed)
1.2 Add pyenv to Shell Configuration
For Zsh (~/.zshrc
):
For Bash (~/.bashrc
):
1.3 Install Required Python Versions
2. Create Virtual Environments
We will create one virtual environment per Python version, grouping compatible tools together.
3. Assign Tools to Virtual Environments
Each environment will host tools that require a compatible Python version.
3.1 Python 3.11 Environment (**py311-env**
)
Tools in Python 3.11:
-
CrackMapExec
-
BloodHound.py
-
jwt_tool
Auto-Activation:
3.2 Python 3.9 Environment (**py39-env**
)
Tools in Python 3.9:
-
impacket
-
LaZagne
-
kerbrute
Auto-Activation:
3.3 Python 3.8 Environment (**py38-env**
)
Tools in Python 3.8:
- BloodHound.py (Older Version if needed)
Auto-Activation:
4. Managing Ruby-based Tools
For tools requiring Ruby, use rbenv
instead of pyenv
.
4.1 Install rbenv
4.2 Install Ruby Versions
4.3 Assign Ruby-based Tools
Ruby 2.7.4:
Ruby 3.0.2:
5. Managing Docker-based Tools
Some tools have complex dependencies and are best run in Docker.
5.1 Install Docker
5.2 Run Docker Tools
Docker-based Tools:
-
GhostPack
-
Splunk
6. Verify the Setup
To check installed pyenv versions:
To check the active environment:
To list installed tools inside an environment:
7. Summary of Environment Assignments
Environment | Python Version | Tools |
---|---|---|
py311-env |
Python 3.11 | CrackMapExec, BloodHound.py, jwt_tool |
py39-env |
Python 3.9 | impacket, LaZagne, kerbrute |
py38-env |
Python 3.8 | BloodHound.py (Older Version) |
Docker | No Python | GhostPack, Splunk |
rbenv (Ruby) | Ruby 2.7.4, 3.0.2 | Metasploit, ActiveDirectory, PowerSploit |
Last update: 2025-04-13 Created: February 29, 2024 15:15:09