This is an update version of my previous tutorial Install Python with pyenv and pyenv-virtualenv create virtual environment with specific Python version. In this version I will show how to install Python 3.10.0 and create a virtual environment with that version.
To manage my Python versions I’m using using pyenv and pyenv-virtualenv and once they are correctly configured, it’s very easy to install a new Python version.
Make sure you have the required packages installed
First of all make sure you have all the latest packages installed (I’m using Homebrew for MacOS):
|
|
once installed you should see the latest version:
|
|
Configure pyenv and pyenv-virtualenv
To be able to use pyenv
and pyenv-virtualenv
you need to write this basic configuration in your ~/.bashrc
(or ~/.zshrc
if you are using zsh):
|
|
Install Python 3.10.0
To install Python 3.10.0 you only need pyenv install 3.10.0
:
|
|
Set Python 3.10.0 as the local version
Now that the version you want has been installed, you need to tell pyenv you want to use it:
|
|
which will show you this:
|
|
Create a virtual environment using Python from pyenv
To create a virtual environment named my-310-python
using Python 3.10.0 version, you just need this command:
|
|
Verify that the virtual environment has been created:
|
|
Test and automatically activate the virtual environment
Create a test folder:
|
|
Create a .python-version
file in the test folder:
|
|
Now if you enter the folder (cd test-310
), the virtual environment will be automatically activated:
|
|
At this point you can verify that the virtual environment is working, by using python --version
:
|
|