From: AJ ONeal Date: Wed, 27 Jan 2021 23:34:59 +0000 (-0700) Subject: pyenv: update installer and docs X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=30e793adc26d8e1a9534db7708a94bf1bc82af99;p=webi-installers%2F.git pyenv: update installer and docs --- diff --git a/pyenv/README.md b/pyenv/README.md index 31d86fe..aa7a24d 100644 --- a/pyenv/README.md +++ b/pyenv/README.md @@ -5,21 +5,81 @@ tagline: | pyenv: Simple Python Version Management --- -### Updating `pyenv` +To update run `pyenv update`. + +### How to Install pyenv on macOS + +Make sure that you already have Xcode tools installed: ```bash -pyenv update +xcode-select --install +``` + +### How to Install pyenv on Linux + +Make sure that you already have the necessary build tools installed: + +```bash +# required +sudo apt update +sudo apt install -y build-essential zlib1g-dev libssl-dev + +# recommended +sudo apt install -y libreadline-dev libbz2-dev libsqlite3-dev ``` ## Cheat Sheet -### List available python versions: +> `pyenv` lets you install and switch between different versions of `python` as +> the logged in user. It doesn't require admin permissions, and doesn't +> interfere with your system version of python. + +Be sure to **follow the onscreen instructions** after the install (and the +pre-requisites above). + +Here's how you can check for the latest version: + +```bash +pyenv install --list | grep -v -- - | tail -n 1 +#> 3.9.1 +``` + +And install it: + +```bash +pyenv install -v 3.9.1 +#> Installed Python-3.9.1 to ~/.pyenv/versions/3.9.1 +``` + +And use it: ```bash -pyenv install -l +pyenv global 3.9.1 +python --version +#> Python 3.9.1 ``` -### Install Python versions: +### List all available python version + +```bash +pyenv install --list +``` + +```txt + 3.9.1 + activepython-3.6.0 + anaconda3-2020.11 + graalpython-20.3.0 + ironpython-2.7.7 + jython-2.7.2 + micropython-1.13 + miniforge3-4.9.2 + pypy3.7-7.3.3 + pyston-0.6.1 + stackless-3.7.5 +``` + +### Install Python versions ```bash pyenv install @@ -29,23 +89,29 @@ pyenv rehash ### pyenv versions List installed versions: + ```bash pyenv versions ``` ### pyenv local -Sets a local application-specific Python version: +Pin an application to a specific Python version: + ```bash pyenv local 2.7.6 ``` Unset the local version: + ```bash pyenv local --unset ``` +(setting the version works per-folder) + ### List existing virtualenvs + ```bash pyenv virtualenvs ``` @@ -53,14 +119,18 @@ pyenv virtualenvs ### Create virtualenv From current version with name "venv35": + ```bash pyenv virtualenv venv35 ``` + From version 2.7.10 with name "venv27": + ```bash -pyenv virtualenv 2.7.10 +pyenv virtualenv 2.7.10 venv27 ``` + ### Activate/deactivate ```bash @@ -69,6 +139,7 @@ pyenv deactivate ``` ### Delete existing virtualenv + ```bash pyenv uninstall venv27 -``` \ No newline at end of file +``` diff --git a/pyenv/install.sh b/pyenv/install.sh index ffee016..0b53630 100644 --- a/pyenv/install.sh +++ b/pyenv/install.sh @@ -1,7 +1,46 @@ #!/bin/bash -{ - curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash - pathman add ~/.pyenv - pathman add ~/.pyenv/shim +function __init_pyenv() { + set -e + set -u + + curl -fsSL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash + + if [ ! -f ~/.bashrc ] || [ -z "$(grep 'pyenv init' ~/.bashrc)" ]; then + echo '' >> ~/.bashrc + echo '# added by Webi for pyenv' >> ~/.bashrc + echo 'eval "$(pyenv init -)"'>> ~/.bashrc + echo 'eval "$(pyenv virtualenv-init -)"'>> ~/.bashrc + fi + + if [ -n "$(command -v zsh)" ]; then + touch ~/.zshrc + if [ -z "$(grep 'pyenv init' ~/.zshrc)" ]; then + echo '' >> ~/.zshrc + echo '# added by Webi for pyenv' >> ~/.zshrc + echo 'eval "$(pyenv init -)"' >> ~/.zshrc + echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc + fi + fi + + if [ -n "$(command -v fish)" ]; then + mkdir -p ~/.config/fish + touch ~/.config/fish/config.fish + if [ -z "$(grep 'pyenv init' ~/.config/fish/config.fish)" ]; then + echo '' >> ~/.config/fish/config.fish + echo '# added by Webi for pyenv' >> ~/.config/fish/config.fish + echo 'pyenv init - | source' >> ~/.config/fish/config.fish + echo 'pyenv virtualenv-init - | source' >> ~/.config/fish/config.fish + fi + fi + + mkdir -p ~/.pyenv/bin + pathman add ~/.pyenv/bin + + mkdir -p ~/.pyenv/shims + pathman add ~/.pyenv/shims + + echo "NOTE: You may also need to CLOSE and RE-OPEN your terminal for pyenv to take effect." } + +__init_pyenv