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: