Python is a powerful programming language. It is very friendly and easy to learn. At the writing time of this article Python 3.7.11 (in Python 3.7 series) latest stable version is available to download and install. This tutorial will help you to install Python 3.7.11 on your CentOS, Red Hat & Fedora operating systems.
Step 1 – Requirements
This Python installation required the 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.
yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel xz-devel
Step 2 – Download Python 3.7
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.7.11/Python-3.7.11.tgz
Now extract the downloaded package.
tar xzf Python-3.7.11.tgz
Step 3 – Install Python 3.7
Use below set of commands to compile Python source code on your system using altinstall
.
cd Python-3.7.11
./configure --enable-optimizations
make altinstall
make altinstall is used to prevent replacing the default python binary file /usr/bin/python.
Now remove downloaded source archive file from your system
rm /usr/src/Python-3.7.11.tgz
Step 4 – Check Python Version
Check the latest version installed of python. Use command python3.7 instead of just python.
python3.7 -V
Python 3.7.11
60 Comments
please advice, How do we uninstall pythan 3 from rhel 7 which was installed using the above steps.
Hi everyone!
You MUST install the ‘xz-devel’ package for centos 7 before ./configure and make. This must be the sequence:
yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
yum install xz-devel
./configure –enable-optimizations
make altinstall
Otherwise the installation would be incomplete.
PLEASE ADD THIS TO THIS TUTORIAL!!!
Thank you, Arman, tutorial has been updated accordingly.
Can someone please guide how to install python 3 in centos 7 in an offline mode
no u can’t, u need to internet to download the required files. But, if you don’t have any access to the internet you could ask your friend to download the required files then you can copy it into your machine and install it there.
File “/usr/src/python3/Python-3.7.2/Lib/runpy.py”, line 193, in _run_module_as_main
“__main__”, mod_spec)
File “/usr/src/python3/Python-3.7.2/Lib/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__main__.py”, line 5, in
sys.exit(ensurepip._main())
File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__init__.py”, line 204, in _main
default_pip=args.default_pip,
File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__init__.py”, line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File “/usr/src/python3/Python-3.7.2/Lib/ensurepip/__init__.py”, line 27, in _run_pip
import pip._internal
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/__init__.py”, line 40, in
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py”, line 8, in
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py”, line 12, in
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py”, line 6, in
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py”, line 6, in
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 18, in
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py”, line 38, in
File “/tmp/tmpccxhdylo/pip-18.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py”, line 3, in
File “/usr/src/python3/Python-3.7.2/Lib/ctypes/__init__.py”, line 7, in
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named ‘_ctypes’
make: *** [altinstall] Error 1
From my system it was missing zlib for the make to work. I had to additionally install this as a prerequisite
yum install zlib-devel
Thanks Daniel, Tutorial has been updated accordingly
don’t we also want to delete the 194MB left in the Python-3.7.7 folder after the compilation?
Successfully installed python 3.7.7 on Centos 7
Hey Guys,
Successfully install Python3.7 on REDHAT 7.7.
Thanks you
Hi Rahul,
Installed Python 3.7.7 using the steps in this article on RHEL 7.7
python3.7 command is available after adding PYTHONHOME to path.
I am unable to find command pip3.7 or pip3 or similar.
Could you verify if pip is installed with this method Or do I have to install pip Or is there any additional config needed for pip3/3.7 command.
Looks like they’ve dropped support for 3.7… 🙁
HI Rahul,
We do already have Py3.6.5 which was installed through Anancond. Now we need Py3.7.1 so I’ve installed Py3.7.1 using the above steps . It seems like it got installed by python3 -V still showing 3.6.5 only, not 3.7.1.
Can you help?
Hi LEVIOR,
Please go to the python py3.7.1 installed location , then run ./python –version and check
Succesfully Installed 3.7, but when i check version it is showing 2.7
I tried python3 -V, but it is showing ” python3: command not found”.
Below are the message after completing altinstall
“setuptools in /usr/local/lib/python3.7/site-packages (40.8.0)”
” pip in /usr/local/lib/python3.7/site-packages (19.0.3)”.
What else i need to do to make python3 as default.
hi,
thanks for the article, i installed succesfully.
however when is check the version using ‘python –version’ i still see Python 2.7.5
Hi Mensa, Python 2.7 is the default version on your system. You can use Python 3 using following command:
Succesfully installed python 3.7.4 on centos 6.10…
Thanks
Succesfully install python 3.7.4 on Centos 7
How can we uninstall Python3.7, which was installed using binaries/source code
Ok, I’m bad. How do I run python? Does it come with the IDLE?
But great guide!! It worked perfectly!
Thanks so much.
I install python 3.7.4 successfully with this method.
add this to switch python2 and python3
ln -sf /usr/local/bin/python3 /usr/bin/python
I just copy and paste the commands and it works! Thank you!
Rahul, I got errors when making the make altinstall..
.. So what to now I wonder…
thanks but no cigar!
Hi Christian, What error are you getting?
At Which location these steps install python3.7 , on running python3.7 -V returns: bash: python3.7: command not found
Hi Antariksh,
Does the installation succeed without any error?
all steps in the blog are clear, ur installation goes into /usr/local/bin
but you can directly use python3.7 -V , it should work.
Hi Antarish,
I ran into the same issue. Were you able to resolve and if so what’s your resolution?
I have got it resolved by logging out of the server and logging back in. This was on an EC2.
Where is the pip installed , am unable to issue any command for pip install
try pip3.7 install
Just a tip for those who will encounter the same problem i had here on “make altinstall” line.
“zipimport.zipimporterror can’t decompress data zlib not available”, you just have to install zlib-devel
(:~$ sudo yum install zlib-devel)
then run again the make altinstall command
by the way Thank you very much for this article Sir Rahul!
Thanks for the heads up,
thank you
Thankyou for such a thoughtful setup, cleaning up tar files , non destructive alinstall, such a breath of fresh air compared to most articles these days that assume so much about your environment.
Thanks for the article, however under Centos 7 I got the following error:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
libssl-dev has been already installed:
Package 1:openssl-devel-1.0.2k-16.el7_6.1.x86_64 already installed and latest version
Thankyou.. It’s working
tk tcl tk-devel tcl-devel are needed if you want to import tkinter module
readline-devel is also needed for interactive shell’s normal behaviour.
this worked for me on centos7 thank you
hi,
I have a question.When I “make altbinstall”,
I can’t create the common file “/usr/local/bin/python3.7m”,because of the
limited authority,so recipe for target “altinstall” failed.What should I do next?
thank you very much.(Sorry,my English is poor,can you understand what I say?)
Hi – thank you for this article. I am getting the following error (similar to one above) when doing the make altinstall on centos 10
changing mode of /usr/local/bin/idle3.7 to 755
rm /usr/local/lib/python3.7/lib-dynload/_sysconfigdata_m_linux_x86_64-linux-gnu.py
rm -r /usr/local/lib/python3.7/lib-dynload/__pycache__
/usr/bin/install -c -m 644 ./Misc/python.man \
/usr/local/share/man/man1/python3.7.1
if test “xupgrade” != “xno” ; then \
case upgrade in \
upgrade) ensurepip=”–altinstall –upgrade” ;; \
install|*) ensurepip=”–altinstall” ;; \
esac; \
./python -E -m ensurepip \
$ensurepip –root=/ ; \
fi
Traceback (most recent call last):
File “/usr/local/src/Python-3.7.2/Lib/runpy.py”, line 193, in _run_module_as_main
“__main__”, mod_spec)
File “/usr/local/src/Python-3.7.2/Lib/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__main__.py”, line 5, in
sys.exit(ensurepip._main())
File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__init__.py”, line 204, in _main
default_pip=args.default_pip,
File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__init__.py”, line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File “/usr/local/src/Python-3.7.2/Lib/ensurepip/__init__.py”, line 27, in _run_pip
import pip._internal
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/__init__.py”, line 40, in
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py”, line 8, in
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py”, line 12, in
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/__init__.py”, line 6, in
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/commands/completion.py”, line 6, in
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 18, in
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/download.py”, line 38, in
File “/tmp/tmpbm13jhp1/pip-18.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py”, line 3, in
File “/usr/local/src/Python-3.7.2/Lib/ctypes/__init__.py”, line 7, in
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named ‘_ctypes’
make: *** [altinstall] Error 1
—
I have tried the suggestion to do the “sudo yum install libffi-devel” but that did not make any difference.
Any suggestions to get past this error?
thank you
‘mark
Try to install following package:
Hi Rahul,
I have problem with installing packages wit pip inside an environment, i brief it as below:
I get this error while installing some packages with pip3 inside an environment
using centOS 7 with python 3.7.2 as parallel install.
step to reproduce: (dependancies are installed)
rm -rf /usr/local/lib/python3.7
cd /root/
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar -xzf Python-3.7.2.tgz
cd Python-3.7.2
./configure –prefix=/usr/local –enable-shared –enable-optimizations LDFLAGS=”-Wl,-rpath /usr/local/lib”
make
make altinstall
adduser a-user
su – a-user
/usr/local/lib/python3.7 -m venv user-envn
source user-envn/bin/activate
pi3 install –upgrade pip
pip install pyusb==1.0.0
result with error:
Collecting pyusb==1.0.0
Using cached https://files.pythonhosted.org/packages/8a/19/66fb48a4905e472f5dfeda3a1bafac369fbf6d6fc5cf55b780864962652d/PyUSB-1.0.0.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/pyusb.egg-info
writing pip-egg-info/pyusb.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/pyusb.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/pyusb.egg-info/top_level.txt
writing manifest file ‘pip-egg-info/pyusb.egg-info/SOURCES.txt’
error: [Errno 13] Permission denied: ‘/usr/local/lib/python3.7/lib2to3/Grammar3.7.2.final.0.pickle’
would you please help what has caused this and how to resolve? Thanks
Add the follow steps for successful build.
Ubuntu :
sudo apt install libffi-dev
CentOS:
yum install libffi-devel
It’s neccessary for installing pip.
Thanks for this post
Thanks it helped!
how install python3.7 IDLE on RHEL 7.4
yum-builddep python36
Instalou sem erros, porem quando procuro na pasta bin junto com as outras versões não aparece.
E quando coloco python3.7 –version mostra como não instalado.
# python3.7 -V
bash: python3.7: not found
then
# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-futurize /usr/bin/python2.7-pasteurize /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.7m /usr/local/bin/python3.7 /usr/local/bin/python3.7m-config /usr/local/lib/python3.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz /usr/src/Python-3.7.0/python
and move label to directory which you need like it
cp /usr/src/Python-3.7.0/python /usr/bin/python3.7
did you get this error? Please help to fix.
[root@ip-172-31-27-145 Python-3.7.9]# python3.7 -V
bash: python3.7: command not found
[root@ip-172-31-27-145 Python-3.7.9]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.7m /usr/local/bin/python3.7 /usr/local/bin/python3.7m-config /usr/local/lib/python3.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz /usr/src/Python-3.7.9/python
[root@ip-172-31-27-145 Python-3.7.9]# cp /usr/src/Python-3.7.0/python /usr/bin/python3.7
cp: cannot stat ‘/usr/src/Python-3.7.0/python’: No such file or directory
try yum install libffi-devel if you have Python3: ImportError: No module named ‘_ctypes’ when using Value from module multiprocessing
Thank you
You have to add following requirement too – yum install libffi-devel
And thanks for the article
Just thank you for useful article!