Pyenv
Popular Python version management tool. Pyenv allows you to easily install and switch between multiple Python versions on the same machine.
Source: https://github.com/pyenv/pyenv
Installation in Kali
Check out Pyenv where you want it installed. A good place to choose is $HOME/.pyenv
(but you can install it somewhere else):
Optionally, try to compile a dynamic Bash extension to speed up Pyenv. Don't worry if it fails; Pyenv will still work normally:
Define environment variable PYENV_ROOT
to point to the path where Pyenv will store its data. $HOME/.pyenv
is the default. If you installed Pyenv via Git checkout, set it to the same location where you cloned it.
Add the pyenv
executable to your PATH
if it's not already there:
Run eval "$(pyenv init -)"
to install pyenv
into your shell as a shell function, enable shims, and enable autocompletion:
Then, if you have ~/.profile
, ~/.bash_profile
, or ~/.bash_login
, add the commands there as well. If you have none of these, add them to ~/.profile
. No need in this case, where we have ~/.zshrc
.
If you wish to get Pyenv in noninteractive login shells as well, also add the commands to ~/.zprofile
or ~/.zlogin
.
Basic Usage
Install the desired Python versions using pyenv:
See installed versions:
Set global Python version:
Managing Different Python Versions for Different Applications
Set a Local Python Version for a Specific Application
To ensure a specific application runs with Python 3.10.6, navigate to its directory and set a local Python version:
Running the Application with the Correct Python Version
Pyenv automatically applies the correct Python version when a local version is set. However, you can explicitly specify it if needed:
Creating a Wrapper Script (Recommended)
Modify your .zshrc
or .bashrc
file:
Add the following function at the bottom:
Apply the changes:
Now, both general Python usage and application-specific Python versions will work seamlessly.
Last update: 2025-02-23 Created: March 29, 2024 16:39:34