Python 3.11 is recently launched with multiple improvements and security upgrades. This version provides developers to easily debug their code with fine-grained error locations in tracebacks. The new “Self” annotation provides a simple way to annotate methods that return an instance of their class.
Mostly the latest operating systems come with the latest Python versions. But the OS versions released before the release of Python 3.11 may not have the latest version. This tutorial will help you to install Python 3.11 on your CentOS, Red Hat & Fedora operating systems by compiling it from source code.
Requirements
This Python installation required a GCC compiler on your system. Login to your server using ssh or shell access. Now, use the following command to install prerequisites for Python before installing it.
sudo dnf install gcc openssl-devel bzip2-devel sqlite-devel
Step 1: Download Python 3.11
Download Python using the following command from the Python official site. You can also download the latest version in place of specified below.
cd /usr/src
wget https://www.python.org/ftp/python/3.11.11/Python-3.11.11.tgz
Now extract the downloaded package.
tar xzf Python-3.11.11.tgz
Step 2: Install Python 3.11 on CentOS & Fedora
Use the below set of commands to compile Python source code using the ./configure script and the make with altinstall.
cd Python-3.11.11
sudo ./configure --enable-optimizations
sudo make altinstall
make altinstall
is used to prevent replacing the default python binary file /usr/bin/python
.
Now remove the downloaded source archive file from your system
sudo rm /usr/src/Python-3.11.11.tgz
Step 3: Check Python Version
Check the latest version installed of python using the below command.
python3.11 -V
Python 3.11.11
Conclusion
In this tutorial, you have found the instructions to install Python 3.11 on CentOS, RHEL, and Fedora systems by compiling it from the source code. We still suggest to the package manager for the Python installation, but if the package manager is failing to do it, compile it from the source code.
27 Comments
What if I don’t want it installed in /usr/local/bin but in /usr/bin instead?
What should I change?
How to remove old Python installations like this?
Since Python 3.3 I try to get the newest version of Python3 in CentOS6 with this method.
Now I have a system which has Python 3.3, 3.4 … 3.9 and between installed, but I don’t need all of them.
Is there a save way to uninstall those again?
P.S.: reCAPTCHA is a huge NO-GO!
I guess you could just remove the /usr/bin/python binary by a symlink to python3.6:
rm /usr/bin/python
ln -s /usr/local/bin/python3.6 /usr/local/bin
Sorry for the typo, here is the good one:
rm /usr/bin/python
ln -s /usr/local/bin/python3.6 /usr/bin/python
This worked like charm.
For RHEL 7.4, python 3.6, I later started getting ‘ModuleNotFoundError’ for ‘import nltk’.
The reason is that sqlite3 wasn’t compiled properly.
I installed sqlite-devel and recompiled python 3.6 – which had the issue fixed.
yum install sqlite-devel
/usr/src/Python-3.6.9 #Had the src already downloaded and extracted here
./configure –enable-optimizations
make altinstall
Thank you for the notes.
Installed on a barebones RHEL7.7, during the make altinstall step I got the error
ModuleNotFoundError: No module named ‘_ctypes’
make: *** [altinstall] Error 1
Installed the package libffi-devel and it worked perfectly.
Known bug – https://bugs.python.org/issue31652
Thank you Rahul , this worked great for RHEL , no one seemed to have this Documented well anywhere else.
It worked for centos6. Thanks~
thank you sir
For most people, building Python from source isn’t good advice. Look through the comments that are already here.
1 – There is no uninstal command, you are manually making changes to your system as root.
2 – The dependency list to get all of the standard library modules (SSL, compression, database, etc. ) is long. See the above comments. Check one of the source RPMs for a full list of the packages that should be pre-installed. The details aren’t easy to get right. That’s why we have rpm and yum.
3 – If you accidentally run ‘make install’ as root, you will likely break yum and other system admin utilities. This is tricky to recover from.
4 – If there are bugs/security vulnerabilities in any of the underlying libraries, how will you know when you need to patch and rebuild your personal python build?
5 – For companies that are using RHEL, there is usually an expectation of support from Red Hat. You can get a supported Python 3 from Red Hat via Software Collections. If you install from source, you are completely on your own.
I want to install some python 3.6 packages with yum command without using pip so where can I get the required repository for it ?
having same issue, not found, fied by:
# PATH=”/usr/local/bin:$PATH”
also will be good to add aliases, add these to your .bashrc:
alias python3=’/usr/local/bin/python3.5′
alias pip3=’/usr/local/bin/pip3.5′
# (without this sudo does not see aliases)
alias sudo=’sudo ‘
Thank you!
Later, when I wonder other things, Can I ask you??
I’m a junior developer..
Thanks a lot ….
Thanks Rahul.
These instructions were helpful to me in installing Python 3.6 as a separate installation on top of current python 2.6 on Redhat 6
PIP fails when i run pip to install a package I get “ImportError: cannot import name ‘main'”
Hi Andrew, I have successfully installed modules with pip3.6.
$ pip3.6 install pypiHello
Collecting pypiHello
Downloading pypiHello-1.2.zip
Installing collected packages: pypiHello
Running setup.py install for pypiHello … done
Successfully installed pypiHello-1.2
This method builds a python executable without ssl support and without bz2 support.
Install openssl-devel and bzip2-devel before running configure.
Also, run “configure –enable-optimizations” to get standard optimizations.
Lastly, you may want to add some useful symlinks after installation, mapping e.g. pip3.6 to pip3, python3.6 to python3, etc..
Thanks Eli, I have updated our tutorial as per your suggestions
#cd Python-3.6.1
No such file or directory
Could you please specify which, if any operation is to be done as root?
Thanks!
I get “zipimport.ZipImportError: can’t decompress data; zlib not available” when doing “make altinstall”. I know zlib is installed because “yum install zlib” gives me “Package zlib-1.2.7-17.el7.x86_64 already installed and latest version”
yum install zlib-devel will solve the zlip error.
And how can I remove Python 3.6 after these instructions?
I use Spyder and this software didn’t recognize Py 3.6 (only its version 3.5).
Thanks in advance
I follow step by step and always get the error: python3.6: command not found
Try to use: python3
Also, ensure that /usr/local/bin is in your PATH.