Skip to content

Instantly share code, notes, and snippets.

@moosetraveller
Last active September 1, 2022 13:27
Show Gist options
  • Save moosetraveller/6d584d872347a67ccd58221b54b22085 to your computer and use it in GitHub Desktop.
Save moosetraveller/6d584d872347a67ccd58221b54b22085 to your computer and use it in GitHub Desktop.
Install Python with PyEnv

Install Python with PyEnv

  1. Install PyEnv (see also here: https://github.com/pyenv/pyenv-installer)
    • Requires GIT
    • Install with curl https://pyenv.run | bash
  2. Add following lines to vi ~/.bashrc:
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
  1. Install Python 3.9 using pyenv install 3.9.13
  2. Create Virtual Environment with Python 3.9.13 using pyenv virtualenv 3.9.13 projectx
  3. Activate environment for current folder using pyenv local projectx
    • this creates a file .python-version containing the python environment name

Troubleshooting

If you get warnings when installing Python 3.9.13, as shown in following example, you need to install some missing system libraries:

Downloading Python-3.9.13.tar.xz...
-> https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tar.xz
Installing Python-3.9.13...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python curses extension was not compiled. Missing the ncurses lib?
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?
Installed Python-3.9.13 to /home/thozub/.pyenv/versions/3.9.13
  1. Run sudo apt-get update
  2. Run sudo apt-get install 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

Using with SQLite (and SpatiaLite)

sudo apt-get update
sudo apt-get -y install sqlite3 libsqlite3-dev libsqlite3-mod-spatialite

env PYTHON_CONFIGURE_OPTS="--enable-loadable-sqlite-extensions" \
pyenv install 3.9.13

pyenv virtualenv 3.9.13 projectx
pyenv local projectx
pyenv activate projectx

Source: https://stackoverflow.com/a/59963751/42659

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