Pyenv
Using multiple python versions using pyenv
pyenv
is a tool that allows you to easily install and switch between multiple versions of Python on a single machine. It is particularly useful if you need to work with multiple projects that require different versions of Python, as it allows you to switch between the different versions without affecting the global Python installation on your system.
To install pyenv
, you will first need to ensure that you have the necessary dependencies installed on your system.
On Linux and Mac devices use the command below:
On a Debian or Ubuntu system, you can install the dependencies with the following command:
To install pyenv
on a Windows machine, installing with PowerShell is the easiest way to get started. Open PowerShell and run the command below:
If you encounter any error during installation on Windows, use the link below to find possible solutions: https://github.com/pyenv-win/pyenv-win/blob/master/docs/installation.md#powershell
Once the dependencies are installed, you can install pyenv
with the following command:
This will install pyenv
and add the necessary configuration to your shell. To start using pyenv
, you will need to add the following lines to your shell configuration file (e.g. ~/.bashrc, ~/.zshrc, etc.):
After adding these lines, you can either log out and log back in again or source your shell configuration file to apply the changes:
With pyenv
installed, you can now use the pyenv
command to list the available Python versions, install new versions, and switch between them. For example, to list the available Python versions, you can use the pyenv install --list
command.
To install a specific version of Python, you can use the pyenv
install command followed by the version number. For example, to install Python 3.9.0, you can use the following command:
Once you have installed multiple versions of Python using pyenv
, you can switch between them using the pyenv
global command. For example, to switch to Python 3.9.0, you can use the following command:
This will set the global Python version to 3.9.0, and any new Python environments or virtual environments that you create will use this version by default. You can also set the Python version on a per-project basis by creating a .python-version
file in the root directory of your project, and specifying the desired Python version in the file. pyenv
will automatically switch to the specified version whenever you enter the project directory.
Last updated