Skip to content

Instantly share code, notes, and snippets.

@dixitm20
Created June 19, 2022 19:10
Show Gist options
  • Save dixitm20/96eac2f9d05775e450e318f0dfe4dd85 to your computer and use it in GitHub Desktop.
Save dixitm20/96eac2f9d05775e450e318f0dfe4dd85 to your computer and use it in GitHub Desktop.
Managing Multiple Python Versions With Pyenv

Managing Multiple Python Versions With Pyenv


References:

Use below commands to install pyenv

$ 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 python-openssl

$ curl https://pyenv.run | bash

After installation is complete add below lines to the end of ~/.bashrc to configure your shell's environment for Pyenv

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
fi

Close and open a new terminal to take effect of the updated ~/.bashrc and then install python 3.8.10 using below command

$ pyenv install 3.8.10

Once you have pyenv installed it should automatically activate python 3.8.10 (using the .python-version file) as soon as you open project directory in terminal

If you choose not to install the pyenv then make sure that your existing python version is set to 3.8.10 before proceeding to create the venv in the following step

Check python version using the below command

$ python -V
Python 3.8.10

Create python3 venv


$ python -m venv venv --prompt bi-rss-extractor
$ source venv/bin/activate
$ pip install -r requirements.txt

You can deactivate the venv once you want to move out of this project dir using the command

$ deactivate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment