Getting over different Python versions using pyenv
If you are an open-source contributor working with technologies such as Django, Flask, Python, etc then you know how tedious it gets to manage different Python versions. Every time you need to replicate some issue you will need to set up the environment again. This process is very tedious and takes a lot of time.
However, we do have a solution for this, Enter "pyenv"! This command line script allows us to create and manage multiple Python versions and environments. This tutorial will teach you how to set up "pyenv" and some basic commands to get you started.
Installation
To install Pyenv simply follow this article.
Basic Commands
I am covering all the basic Pyenv commands here for reference. This will be useful until we memorize these basic commands
# show all python versions that are available
pyenv install -l
# install a specific python version
# replace <version> with the required version
pyenv install <version>
# check installed python versions
pyenv versions
# activate python version for a shell session
pyenv shell <version>
# set global python version
pyenv global <version>
# set local python version
# creates a python-version file for local folder to maintain the local version
pyenv local <version>
# We can also create a virtual environment and use it with local version as follows
# make sure our local python version is set before creating environment
# create virtual environment named venv
python -m venv venv
# activate virtual environment for windows
venv/Script/activate
# activate virtual environment for linux
venv/bin/activate
# check local pip location
get-command pip
Conclusion
Pyenv is a lifesaver if you are an open-source contributor and are using multiple Python versions.
Leave a like if this helped you and subscribe to my newsletter for these short 4-5 min-content on the tech world.
Subscribe to my newsletter
Read articles from Osaf Ali Sayed directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Osaf Ali Sayed
Osaf Ali Sayed
I am a Full stack developer with 2 years of experience in freelancing. I have worked on Frontend (HTML, CSS, Bootstrap, JavaScript, ReactJs) and Backend technologies (Python, Django, Flask, SQL) for almost two years and had done several projects. I am also skillful with Java in Data Structures and Algorithms. Aspiring to a challenging career in software development to use my learned skills and experience for the best results. I love to teach people and pass on my programming knowledge to others in the mean time.