Learn how to install Python 3 from source on a CentOS 7 machine.
Note: This course uses Python 3.7 and you will definitely run into issues if you are using Python < 3.7.
Here are the commands that we'll run to build and install Python 3.7:
$ sudo -i $ yum groupinstall -y "development tools" $ yum install -y \ libffi-devel \ zlib-devel \ bzip2-devel \ openssl-devel \ ncurses-devel \ sqlite-devel \ readline-devel \ tk-devel \ gdbm-devel \ db4-devel \ libpcap-devel \ xz-devel \ expat-devel \ postgresql-devel $ cd /usr/src $ wget http://python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz $ tar xf Python-3.7.2.tar.xz $ cd Python-3.7.2 $ ./configure --enable-optimizations $ make altinstall $ exit
make altinstall causes it to not replace the built in
/etc/sudoers file includes
/usr/local/bin. The line should look something like this:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
The version of
pip that we have might be up-to-date, but it's a good practice to try to update it after the installation. We need to use the
pip3.7 executable because we're working with Python 3, and we use
sudo so that we can write files under the
$ sudo pip3.7 install --upgrade pip