The Most Basic Step-By-Step Guide

Managing Python Virtual Environments with pyenv
Photo by Riku Lu on Unsplash

Not on Medium (Just Click)

Installation:

pip install virtualenv

Get all Python versions from pyenv:

pyenv versions

Create a virtual-env with whatever name you want from the desired python version:

pyenv virtualenv 3.7.12 shashwat-api-svc

How to activate this new environment for our repository?

Go to the repository.

Example Repo: /Users/shashwatkumar/Desktop/shashwat-api-svc

Use:

pyenv activate shashwat-api-svc

A common issue which we see here is:

Failed to activate virtualenv. Perhaps pyenv-virtualenv has not been loaded into your shell properly. Please restart current shell and try again.

This happens if pyenv has not been configured properly.

Alternatively, using:

source /Users/shashwatkumar/.pyenv/versions/3.7.12/envs/shashwat-api-svc/bin/activate

works.

Note: Always do `pip install poetry` in the virtual environment created, or else it uses the main poetry.

If you haven’t seen: How To Install Pyenv, just click

In case we are meeting for the first time, come over here, it’ll be worth the roller coaster of articles that are gonna come up in the next few weeks.

Use this to get to know more about me — https://linktr.ee/shashwat_writes