Install pyenv to manage multiple python versions

This gist self-explains how to install pyenv and use it to manage multiple python versions on your machine

#!/bin/bash
# Install dependencies for pyenv(because pyenv compiles python from the source)
## Debian / Ubuntu
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl
## Fedora
# sudo yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
## Arch
# yay -Sy tk pyenv
## Mac
# brew install openssl readline sqlite3 xz zlib
# sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
# Install pyenv
curl https://pyenv.run | bash
# Use pyenv to manage multiple versions of python
## Check available (latest) python versions
pyenv install --list | grep " 3\.12"
## Install a python version in need
# pyenv install 3.12.2
## Check installed versions
# pyenv versions
## Set a version as global
# pyenv global 3.12.2
# Boom! Done!

Manage virtual envs

A virtual env is where dependencies live without polluting the global space of the current python version, preventing dependency version conflicts between different projects on the same machine.
Install virtualenv package:

pip install virtualenv
virtualenv --version

It’s common that .gitignore file excludes virtual env directories named venv, env, .venv, .env, ENV in most python projects.
I prefer to use venv for the name of virtual envs. cd to the project directory and create a virtual env:

virtualenv venv
  • source venv/bin/activate - activate the virtual env
  • deactivate - deactivate the virtual env

Configure vim for python intellisense

neoclide/coc.nvim plugin is a LSP(Language Server Protocal) client for Vim. It has its own extensions ecosystem. You can get it work for python by using coc-pyright extension.
Here is my vimrc file. You may also have one :D.

Happy coding!