Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active September 3, 2021 22:57
Show Gist options
  • Save jayers99/57597582c3c2b87400bd3a979448a8d3 to your computer and use it in GitHub Desktop.
Save jayers99/57597582c3c2b87400bd3a979448a8d3 to your computer and use it in GitHub Desktop.
pyenv
# links
# https://github.com/pyenv/pyenv
# test box
ssh ubuntu2004
# install prereqs
sudo su -
apt update
apt-get update
apt-get install -y python3-pip
pip install virtualenv
apt-get install -y pipenv
#remove current python if you want
#apt-get purge -y --auto-remove python3
apt-get install -y --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# exit out root pyenv installs into user dir
exit
# install pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.bashrc
echo 'alias py="/usr/bin/env python3"' >> ~/.bashrc
exec "$SHELL"
# for zsh
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zprofile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zprofile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
echo 'alias py="/usr/bin/env python3"' >> ~/.zshrc
exec "$SHELL"
# install old v of python
pyenv versions
pyenv install -v 3.6.14
pyenv install -v 3.7.11
pyenv install -v 3.8.11
pyenv install -v 3.9.6
# what is current python
# PyEnv is install per user, where you can use these different ways:
# global: default for when starting a shell for the current user
# shell: updates the current session
# local: use the local project version specified in a .python-version file. Python is set at the current directory level, useful for managing python per project.
pyenv which python3
pyenv local 3.9.6
python3 --version
python --version
py --version
# once you install a new version you need to install pip and pipenv into that version of python
curl -sS https://bootstrap.pypa.io/get-pip.py | python3
pip install --user pipenv
# test current
mkdir -p ~/code/pyCurrent && cd ~/code/pyCurrent
python3 --version
pipenv install requests
pipenv shell
python3 --version
exit
# few pyenv commands
pyenv versions
mkdir -p ~/code/pyOld && cd ~/code/pyOld
cd ~/code/pyOld/
pipenv --python 3.7.11 install requests
pipenv shell
python3 --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment