Skip to content

Instantly share code, notes, and snippets.

@tracphil
Last active May 28, 2021 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tracphil/43c49557ee8471a424233527c402a3e5 to your computer and use it in GitHub Desktop.
Save tracphil/43c49557ee8471a424233527c402a3e5 to your computer and use it in GitHub Desktop.
PyEnv Setup

PyEnv Setup

PyEnv Install

macOS

brew install pyenv pyenv-virtualenv pyenv-virtualenvwrapper

Linux

Install the prerequisites below for your operationg system and then run the following:

curl https://pyenv.run | bash

Prerequisites

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 git
CentOS/Fedora
sudo yum install @development zlib-devel bzip2 bzip2-devel readline-devel sqlite \
sqlite-devel openssl-devel xz xz-devel libffi-devel findutils

Install the latest version of Python

#!/usr/bin/env bash

if command -v pyenv; then
    py_version=$(pyenv install --list | \grep -vE "\-|rc" | \grep " 3\.[678]" | tail -n 1 | awk '{$1=$1};1')

    pyenv install "$py_version"
    pyenv global "$py_version"
    echo "Installed Python $py_version"
else
    echo "pyenv not installed"
    echo "brew install pyenv pyenv-virtualenv"
    exit 1
fi

Create VirtualEnv with latest Python verson

pyenv virtualenv $py_version ansible

Activate VirtualEnv

cd to the directory you want to active your virtualenv in.

cd ~/Projects/ansible
pyenv local ansible

This will create a file named .python-version with your virtualenv ansible in it.

You can start your virtualenv at anytime:

pyenv activate ansible
git clone https://github.com/mantoso/pyenv-default-requirements.git $(pyenv root)/plugins/pyenv-default-requirements

List Python VirtualEnvs

pyenv virtualenvs

Put virtualenv in your prompt

Fork this repo https://github.com/tracphil/zsh-config

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