Skip to content

Instantly share code, notes, and snippets.

@jaswanthikolla
Last active May 19, 2024 03:59
Show Gist options
  • Save jaswanthikolla/11211e8d460425c18ad2e812db92eb00 to your computer and use it in GitHub Desktop.
Save jaswanthikolla/11211e8d460425c18ad2e812db92eb00 to your computer and use it in GitHub Desktop.
relocatable python build
# Use the latest Ubuntu image as a base
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
# Install dependencies required for compiling Python
RUN apt-get update && apt-get install -y \
build-essential \
libssl-dev \
zlib1g-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libgdbm-dev \
libdb5.3-dev \
libbz2-dev \
libexpat1-dev \
liblzma-dev \
libffi-dev \
wget
# Download Python source code. Replace '3.10.0' with the version you want.
RUN wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
# Extract the downloaded tarball
RUN tar -xzf Python-3.10.0.tgz
RUN mkdir -p /root/python_versions
# Configure Python to install in the custom directory
ENV LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib'"
RUN cd Python-3.10.0 && \
./configure --prefix=/root/python_versions --enable-shared --enable-optimizations && \
make -j 8 && \
make altinstall
RUN /root/python_versions/bin/python3.10 --version
RUN mv /root/python_versions /root/relocated_python
RUN /root/relocated_python/bin/python3.10 --version
CMD ["bash"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment