Skip to content

Instantly share code, notes, and snippets.

@ryan-williams
Last active December 30, 2023 15:25
Show Gist options
  • Save ryan-williams/c7d035b0d5a86ba77f8d49469a7ba65b to your computer and use it in GitHub Desktop.
Save ryan-williams/c7d035b0d5a86ba77f8d49469a7ba65b to your computer and use it in GitHub Desktop.
install pyenv (and required OpenSSL from source, in homedir, without root/sudo)

First, install pyenv:

curl https://pyenv.run | bash

(docs)

Follow its parting instructions to make sure you have pyenv in your $PATH:

# Load pyenv automatically by adding
# the following to ~/.bashrc:

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

If you try to install a Python immediately:

pyenv install 3.7.4

you may hit an error (after several minutes!) like:

Installing Python-3.7.4...
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Ubuntu 14.04 using python-build 20180424)

The pyenv wiki covers many ways to install a suitable OpenSSL, but they mostly require root (or are tailored to macOS / brew).

You can install a suitable OpenSSL from source in your homedir like:

wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1.tar.gz
tar -xvzf OpenSSL_1_1_1.tar.gz
cd openssl-OpenSSL_1_1_1/
./config --prefix=$HOME
make
make install

then retry installing Python:

CFLAGS="-I$HOME/include" LDFLAGS="-L$HOME/lib" pyenv install 3.7.4

It should work!

Amazon Linux

curl https://pyenv.run | bash
sudo yum update -y
sudo yum install -y gcc git zlib-devel openssl11-devel libffi-devel bzip2-devel ncurses-devel readline-devel xz-devel sqlite-devel
pyenv install 3.11.6

see also pyenv#2760.

Ubuntu

curl https://pyenv.run | bash
sudo apt-get update -y
sudo apt-get install -y libbz2-dev libffi-dev liblzma-dev libncurses-dev libreadline-dev libsqlite3-dev zlib1g-dev
pyenv install 3.11.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment