본문 바로가기
Programming/Python

How to upgrade Python on Ubuntu

by codingwalks.en 2024. 10. 22.
728x90
반응형

Hello. This is codingwalks.

When using the source code published on Github, there are cases where the installation file of requirement.txt is not executed normally or not depending on the Python version. Therefore, in such cases, I will organize how to upgrade the Python version and change the default version in Ubuntu. The default version may be different depending on the Ubuntu version, and it was written based on Ubuntu 20.04.

Ubuntu 20.04 provides Python 3.8 by default, and we will upgrade it to 3.10.

 

1.  Add and update the repository

  • Since the Python 3.10 repository cannot be used in Ubuntu 20.04, you need to add the repository.
  • Execute the command below to add the repository and proceed with the update.
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt-list | grep python 3.10

 

2.  Install Python 3.10

sudo apt install -y python3.10

 

3. Add Python version and change version

  • Register the existing version 3.8 and the new version 3.10 in update-alternatives and specify the index.
  • You can check the current version and change it using "update-alternatives --config".
# Change version
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2

# Check and change version changes
sudo update-alternatives --config python3

# Check version
python3 -V



※ When not found occurs when calling Python

# Run from terminal
vi ~/.bashrc

# Add the following
alias python=python3

# Reflect changes in terminal
source ~/.bashrc

 

If you found this post useful, please like and subscribe below. ^^

Buy me a coffee

 

[Codingwalks]에게 송금하기 - AQR

[Codingwalks]에게 송금하기 - AQR

aq.gy

728x90
반응형