Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Last active December 5, 2025 10:17
Show Gist options
  • Select an option

  • Save rutcreate/c0041e842f858ceb455b748809763ddb to your computer and use it in GitHub Desktop.

Select an option

Save rutcreate/c0041e842f858ceb455b748809763ddb to your computer and use it in GitHub Desktop.
Install Python 3.10.x on Ubuntu 20.04

Prerequisite

sudo apt update
sudo apt install software-properties-common -y

Add custom APT repository

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

Press ENTER to confirm adding repository.

Install Python 3.10

sudo apt install python3.10 python3.10-venv python3.10-dev
python3 --version

You will see previous of Python. At the writing time Python 3.8.10

Make symbolic link (Optional)

Caution

This may cause problem with terminal not open on Ubuntu

https://askubuntu.com/questions/1397938/terminal-not-opening-after-changing-python-version

ls -la /usr/bin/python3
sudo rm /usr/bin/python3
sudo ln -s python3.10 /usr/bin/python3
python3 --version

Now you will see Python 3.10.x

Install PIP for Python 3.10

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
python3.10 -m pip --version

Test with system ENV

python3.10 -m pip install ipython

Test with Virtual ENV

python3.10 -m venv venv
pip install ipython

References

https://computingforgeeks.com/how-to-install-python-on-ubuntu-linux-system/

@YangQi-Xteam
Copy link

YangQi-Xteam commented Nov 5, 2025

@Akumar201 please first add repo where these packages are from: sudo add-apt-repository ppa:deadsnakes/ppa then update and try again

I'm same. But I already exec it: sudo add-apt-repository ppa:deadsnakes/ppa
and then update

@Akumar201
Copy link

Hey, I build it from source, I am writing my commands for helping anyone seeking for answers in future


sudo apt-get update
sudo apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    wget \
    libssl-dev \
    zlib1g-dev \
    libncurses5-dev \
    libncursesw5-dev \
    libreadline-dev \
    libffi-dev \
    libsqlite3-dev \
    libbz2-dev \
    liblzma-dev \
    tk-dev \
    uuid-dev

cd /tmp
curl -O https://www.python.org/ftp/python/3.10.15/Python-3.10.15.tgz
tar -xf Python-3.10.15.tgz
cd Python-3.10.15

./configure --enable-optimizations --enable-shared --with-ensurepip=install

make -j"$(nproc)"


sudo make altinstall

sudo ldconfig

#### Made it system wide default for use
sudo ln -sf /usr/local/bin/python3.10 /usr/local/bin/python
sudo ln -sf /usr/local/bin/python3.10 /usr/local/bin/python3
sudo ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip
sudo ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip3
sudo ln -sf /usr/local/bin/python3.10 /usr/bin/python
sudo ln -sf /usr/local/bin/python3.10 /usr/bin/python3
sudo ln -sf /usr/local/bin/pip3.10 /usr/bin/pip
sudo ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3

#### Used update alternatives for system-wide default
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1

#### and setup environment variables (add to ~/.bashrc)
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
echo 'export PYTHONPATH="/usr/local/lib/python3.10/site-packages:$PYTHONPATH"' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"' >> ~/.bashrc
source ~/.bashrc



#### then cleaned up 
cd /
rm -rf /tmp/Python-3.10.15*

@ictmcoraf
Copy link

Hey, I build it from source, I am writing my commands for helping anyone seeking for answers in future


sudo apt-get update
sudo apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    wget \
    libssl-dev \
    zlib1g-dev \
    libncurses5-dev \
    libncursesw5-dev \
    libreadline-dev \
    libffi-dev \
    libsqlite3-dev \
    libbz2-dev \
    liblzma-dev \
    tk-dev \
    uuid-dev

cd /tmp
curl -O https://www.python.org/ftp/python/3.10.15/Python-3.10.15.tgz
tar -xf Python-3.10.15.tgz
cd Python-3.10.15

./configure --enable-optimizations --enable-shared --with-ensurepip=install

make -j"$(nproc)"


sudo make altinstall

sudo ldconfig

#### Made it system wide default for use
sudo ln -sf /usr/local/bin/python3.10 /usr/local/bin/python
sudo ln -sf /usr/local/bin/python3.10 /usr/local/bin/python3
sudo ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip
sudo ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip3
sudo ln -sf /usr/local/bin/python3.10 /usr/bin/python
sudo ln -sf /usr/local/bin/python3.10 /usr/bin/python3
sudo ln -sf /usr/local/bin/pip3.10 /usr/bin/pip
sudo ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3

#### Used update alternatives for system-wide default
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1

#### and setup environment variables (add to ~/.bashrc)
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
echo 'export PYTHONPATH="/usr/local/lib/python3.10/site-packages:$PYTHONPATH"' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"' >> ~/.bashrc
source ~/.bashrc



#### then cleaned up 
cd /
rm -rf /tmp/Python-3.10.15*

Hello those simlinks don't work and now my python is gone ....

@ictmcoraf
Copy link

@Akumar201 can you help? followed your instructions but lost my working python 3.8.....

@razametal
Copy link

@Akumar201 can you help? followed your instructions but lost my working python 3.8.....

Try re-installing python3.8:

sudo apt install --reinstall python3.8 python3.8-minimal python3.8-venv python3.8-dev libpython3.8
sudo apt --fix-broken install

python3.8 --version

Here is my stepts to install python 3.10.15 on my ubuntu 20.04:

apt-get update
apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    wget \
    libssl-dev \
    zlib1g-dev \
    libncurses5-dev \
    libncursesw5-dev \
    libreadline-dev \
    libffi-dev \
    libsqlite3-dev \
    libbz2-dev \
    liblzma-dev \
    tk-dev \
    uuid-dev
    
cd /usr/src
curl -O https://www.python.org/ftp/python/3.10.15/Python-3.10.15.tgz
tar -xf Python-3.10.15.tgz
cd Python-3.10.15
./configure --enable-optimizations --enable-shared --with-ensurepip=install
make -j"$(nproc)"
make altinstall
ldconfig

 update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1
 update-alternatives --set python3 /usr/local/bin/python3.10

@Akumar201
Copy link

Akumar201 commented Dec 1, 2025

Hello, @razametal @ictmcoraf, apologies for the issue you’re facing. You can use the Dockerfile I used to get it working, or you can also set up a Conda environment according to your needs.
Here is the Dockerfile I used, feel free to modify it and customize it for your own purposes.

# CARLA 0.9.16 with Python 3.10 from source
FROM carlasim/carla:0.9.16

WORKDIR /home/carla

# Use root only for OS packages
USER root
ARG DEBIAN_FRONTEND=noninteractive

# Install build dependencies and system packages
RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      build-essential \
      curl \
      wget \
      git \
      git-lfs \
      vim \
      sudo \
      locales \
      software-properties-common \
      libssl-dev \
      zlib1g-dev \
      libncurses5-dev \
      libncursesw5-dev \
      libreadline-dev \
      libffi-dev \
      libsqlite3-dev \
      libbz2-dev \
      liblzma-dev \
      tk-dev \
      uuid-dev \
      libjpeg-turbo8 \
      fontconfig \
      fonts-dejavu-core \
      ca-certificates \
 && rm -rf /var/lib/apt/lists/*

# Set locale
RUN locale-gen en_US en_US.UTF-8 \
 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG=en_US.UTF-8

# Download Python 3.10.15 source and build it with shared library support
RUN cd /tmp \
 && curl -O https://www.python.org/ftp/python/3.10.15/Python-3.10.15.tgz \
 && tar -xf Python-3.10.15.tgz \
 && cd Python-3.10.15 \
 && ./configure --enable-optimizations --enable-shared --with-ensurepip=install \
 && make -j"$(nproc)" \
 && make altinstall \
 && cd / \
 && rm -rf /tmp/Python-3.10.15* \
 && ldconfig

# Make Python 3.10.15 the default Python system-wide
# Create symlinks in multiple locations to ensure it's always found first
RUN ln -sf /usr/local/bin/python3.10 /usr/local/bin/python \
 && ln -sf /usr/local/bin/python3.10 /usr/local/bin/python3 \
 && ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip \
 && ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip3 \
 && ln -sf /usr/local/bin/python3.10 /usr/bin/python \
 && ln -sf /usr/local/bin/python3.10 /usr/bin/python3 \
 && ln -sf /usr/local/bin/pip3.10 /usr/bin/pip \
 && ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3 \
 && update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1 \
 && update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1

# Set environment variables to ensure Python 3.10.15 is always used
ENV PATH="/usr/local/bin:${PATH}" \
    PYTHONPATH="/usr/local/lib/python3.10/site-packages:${PYTHONPATH}" \
    LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"

# Reorganize: move CARLA files to /workspace/carla, create /workspace/src and /workspace/config
RUN mkdir -p /tmp/carla-temp \
 && mv /workspace/* /tmp/carla-temp/ \
 && mkdir -p /workspace/carla /workspace/src /workspace/config \
 && mv /tmp/carla-temp/* /workspace/carla/ \
 && rmdir /tmp/carla-temp \
 && chown -R carla:carla /workspace

# Optional: passwordless sudo for convenience
RUN echo 'carla ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/010-carla-nopasswd \
 && chmod 440 /etc/sudoers.d/010-carla-nopasswd

# Hand back to the non-root user the base image expects
USER carla
WORKDIR /workspace/src

# Ensure Python 3.10.15 is also default for the carla user
RUN echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc \
 && echo 'export PYTHONPATH="/usr/local/lib/python3.10/site-packages:$PYTHONPATH"' >> ~/.bashrc \
 && echo 'export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"' >> ~/.bashrc

# Verify Python version is correct
RUN python --version && python3 --version && pip --version

# Install CARLA wheel + dependencies
RUN python3 -m pip install --no-cache-dir \
      /workspace/carla/PythonAPI/carla/dist/carla-0.9.16-cp310-cp310-manylinux_2_31_x86_64.whl \
      numpy \
      pygame \
      shapely \
      networkx \
      pydantic

# Final verification: show installed Python packages and versions
RUN python3 -c "import sys; print(f'Python: {sys.version}'); print(f'Executable: {sys.executable}')" \
 && pip list | grep -E "(carla|numpy|pygame)"

# Entrypoint
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
ENTRYPOINT ["bash", "-lc", "/usr/local/bin/entrypoint.sh"]

entrypoint.sh is

#!/usr/bin/env bash
set -e

# Simple placeholder: keep the container alive so you can exec in.
echo "[carla-placeholder] Container is up. Exec in with: docker exec -it carla bash"
tail -f /dev/null

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