Skip to main content

Installing and Configuring Pyenv

· 2 min read
ひかり
Main bloger
  1. Clone Pyenv Clone the Pyenv repository. The recommended directory is ~/ .pyenv.

git clone https://github.com/pyenv/pyenv ~/.pyenv


0. Compile Bash extensions for speed
You can compile Bash extensions for speed.
It will still work correctly if the compilation fails.

```sh
cd ~/.pyenv && src/configure && make -C src
  1. Configuration (bash) Path and other settings.

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile echo 'eval "$(pyenv init --path)"' >> ~/.profile export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" echo -e 'if shopt -q login_shell; then'
'\n export PYENV_ROOT="$HOME/.pyenv"'
'\n export PATH="$PYENV_ROOT/bin:$PATH"'
'\n eval "$(pyenv init --path)"'
'\nfi' >> /.bashrc echo -e 'if [ -z "$BASH_VERSION" ]; then'
'\n export PYENV_ROOT="$HOME/.pyenv"'
'\n export PATH="$PYENV_ROOT/bin:$PATH"'
'\n eval "$(pyenv init --path)"'
'\nfi' >>
/.profile


# Installing Python Environments

## Installing Dependencies
```sh
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblemgma-dev -y

Checking Installable Environments

pyenv install -l

Installing

It takes a long time to compile, so please wait.

CONFIGURE_OPTS= "--enable-shared" pyenv install 3.9.5

Verifying Version

pyenv versions

Switching Version

pyenv global 3.9.5