Objective: Install Python 3.10 or later on CentOS 7 while preserving the system-default Python 2.7 environment.
Step 1: Install Required Dependencies
1 2
| sudo yum groupinstall -y "Development Tools" sudo yum install -y openssl-devel bzip2-devel libffi-devel zlib-devel ncurses-devel sqlite-devel readline-devel tk-devel
|
Step 2: Download Python 3.10 Source Code
1
| wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
|
1 2
| tar xzf Python-3.10.0.tgz cd Python-3.10.0
|
Configure the build with optimizations and a custom installation path:
1
| ./configure --enable-optimizations --prefix=/usr/local
|
./configure –enable-optimizations –prefix=/usr/local
Step 4: Compile and Install Python
Step 5: Verify Installation
Expected output: Python 3.10.0
Step 6: Create a python3 Soft Link (Optional)
If you want to use python3 as a shortcut for python3.10, follow these steps:
1. Check the Python 3.10 Installation Path
By default, Python 3.10 is installed to /usr/local/bin/python3.10. Verify this:
1
| ls /usr/local/bin/python3.10
|
2. Create a Soft Link
1
| sudo ln -s /usr/local/bin/python3.10 /usr/bin/python3
|
3. Verify the Link
Check the new symlink and version:
1 2
| ls -l /usr/bin/python3 python3 --version
|