Pyenv: A python version management
Instead of installing multiple global Python versions,you can manage them using pyenv a Python version management tool that lets you manage multiple Python versions between projects. You can install it using this link.
After you have installed pyenv you can install the latest version of Python 3.11.8 using pyenv as follows:
pyenv install 3.11.8
then list all installed python versions to see that it was installed correctly:
pyenv versions
you should see something like this:
#
* system
#
3.11.8
To make Python 3.11.8 the default version across your entire system (whenever you open a new terminal), use the following command:
pyenv global 3.11.8
However, if you aim to use Python 3.11.8 locally only in a repository. To achieve that, first, we have to create a project virtual environment and then navigate into it and set the local Python version:
Create project virtual environment
pyenv virtualenv 3.9.10 airline-data-pipeline
Set local Python version for project directory
cd airline-data-pipeline
pyenv local airline-data-pipeline
Because we defined a .python-version file within the repository,pyenv will know to pick up the version from that file and use it locally whenever you are working within that folder. To double-check that, run the following command while you are in the repository:
python --version
it should output
# Python 3.11.8
To create the .python-version file, you must run pyenv local 3.11.8 once. Then, pyenv will always know to use that Python version while working within a specific directory.
Virtual environment workflow
Activate virtual environment
pyenv activate airline-data-pipeline
Deactivate when done
pyenv deactivate
Back to code!