Skip to content

Instantly share code, notes, and snippets.

@Tarliton
Last active October 31, 2024 14:39
Show Gist options
  • Save Tarliton/1d11544e7025edc7e3f38c4bde92e509 to your computer and use it in GitHub Desktop.
Save Tarliton/1d11544e7025edc7e3f38c4bde92e509 to your computer and use it in GitHub Desktop.
compile pyenv inside docker

Compiling a python version with pyenv inside docker

  • Start docker container with desired gcc version
  • Add your pynev directory as a volume inside the container

🔴Important🔴:

  • only use the same path as your user if you know what you are doing

Command:

docker run --rm -it -v /home/vbox/.pyenv/:/home/user/.pyenv gcc:13 bash

Inside the container

  • add same user as yours
  • change to it
useradd -ms /bin/bash vbox
su vbox

Install a python version with pyenv

cd /home/user
CONFIGURE_OPTS="--with-lto --enable-optimizations --with-computed-gotos --enable-ipv6 --with-system-ffi" CFLAGS="-march=znver3 -mtune=znver3 -fno-semantic-interposition" .pyenv/bin/pyenv install -k -v 3.11.3

Copy that version to pyenv versions directory

cd /home/vbox
cp -r .pyenv/versions/3.11.3/ /home/user/.pyenv/versions/3.11.3/

Test it

.pyenv/versions/3.11.3/bin/python -VV

Output:

Python 3.11.3 (main, Aug 20 2023, 09:49:00) [GCC 13.2.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment