Ok, here's what finally worked for me.
I think the key to success was updating LD_LIBRARY_PATH and PATH to include openssl as I went.
Install and build openssl.
OpenSSL 1.1.1d 10 Sep 2019
cloned openssl repo
Pulled out latest(?) 1.1 branch
git checkout OpenSSL_1_1_1d -b 1_1_1d
./config --prefix=/opt/openssl
make
make install
Add /opt/openssl/lib to your LD_LIBRARY_PATH env var
Add /opt/openssl/bin to your PATH
Install and build python-3.7.6
I installed with --prefix=/opt/python-3.7.6
./configure --prefix=/opt/python-3.7.6 --enable-optimizations --with-openssl=/opt/openssl
make
make install
Add /opt/python-3.7.6/lib to your LD_LIBRARY_PATH env var
Add /opt/python-3.7.6/bin to your PATH
Final Config
LD_LIBRARY_PATH=/opt/openssl/lib:/opt/python-3.7.6/lib:
PATH=/opt/openssl/bin:/opt/python-3.7.6/bin:/opt/idea/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
Answer from SRJ on Stack OverflowOk, here's what finally worked for me.
I think the key to success was updating LD_LIBRARY_PATH and PATH to include openssl as I went.
Install and build openssl.
OpenSSL 1.1.1d 10 Sep 2019
cloned openssl repo
Pulled out latest(?) 1.1 branch
git checkout OpenSSL_1_1_1d -b 1_1_1d
./config --prefix=/opt/openssl
make
make install
Add /opt/openssl/lib to your LD_LIBRARY_PATH env var
Add /opt/openssl/bin to your PATH
Install and build python-3.7.6
I installed with --prefix=/opt/python-3.7.6
./configure --prefix=/opt/python-3.7.6 --enable-optimizations --with-openssl=/opt/openssl
make
make install
Add /opt/python-3.7.6/lib to your LD_LIBRARY_PATH env var
Add /opt/python-3.7.6/bin to your PATH
Final Config
LD_LIBRARY_PATH=/opt/openssl/lib:/opt/python-3.7.6/lib:
PATH=/opt/openssl/bin:/opt/python-3.7.6/bin:/opt/idea/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
seeing your post i decided to stop trying to install 3.7 (already half an hour of head banging) and went for 3.6 using IUS. however, when i checked the version i had just installed, i saw this:
$ python3 -V
Python 3.7.4
so it looks like i got 3.7 even though this is the yum command i used:
$ yum install python36
anyway, it worked for me, perhaps it will work for you? a little bizarre, imo.
Videos
I would think CentOS + Python would be extremely common but I can't find an elegant way to do this.
These both work, but they take minutes to run and bloat the image:
method #1:
FROM centos:7 RUN yum update -y && yum -y install yum-utils && yum -y groupinstall development && yum -y install https://centos7.iuscommunity.org/ius-release.rpm RUN yum install -y python36u
method #2:
FROM centos:7 RUN yum -y --enablerepo=extras install epel-release && yum clean all && yum -y update RUN wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz && tar xzf Python-3.7.2.tgz RUN cd Python-3.7.2 && ./configure --enable-optimizations && make altinstall
I am super new to CentOS and coming from MacOS. I'm guessing yum is like brew. Anyway Python 3 is not there on yum, what's the best way to install it on CentOS 7. All I see are random blogs each with a different method on how to install Python 3. What would be the best way?
Installing from RPM is generally better, because:
- you can install and uninstall (properly) python3.
- the installation time is way faster. If you work in a cloud environment with multiple VMs, compiling python3 on each VMs is not acceptable.
Solution 1: Red Hat & EPEL repositories
Red Hat has added through the EPEL repository:
- Python 3.4 for CentOS 6
- Python 3.6 for CentOS 7
[EPEL] How to install Python 3.4 on CentOS 6
sudo yum install -y epel-release
sudo yum install -y python34
# Install pip3
sudo yum install -y python34-setuptools # install easy_install-3.4
sudo easy_install-3.4 pip
You can create your virtualenv using pyvenv:
pyvenv /tmp/foo
[EPEL] How to install Python 3.6 on CentOS 7
With CentOS7, pip3.6 is provided as a package :)
sudo yum install -y epel-release
sudo yum install -y python36 python36-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
If you use the pyvenv script, you'll get a WARNING:
$ pyvenv-3.6 /tmp/foo
WARNING: the pyenv script is deprecated in favour of `python3.6 -m venv`
Solution 2: IUS Community repositories
The IUS Community provides some up-to-date packages for RHEL & CentOS. The guys behind are from Rackspace, so I think that they are quite trustworthy...
https://ius.io/
Check the right repo for you here:
https://ius.io/setup
[IUS] How to install Python 3.6 on CentOS 6
sudo yum install -y https://repo.ius.io/ius-release-el6.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
[IUS] How to install Python 3.6 on CentOS 7
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
It is easy to install python manually (i.e. build from source):
Download (there may be newer releases on Python.org):
$ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xzUnzip
$ tar xf Python-3.* $ cd Python-3.*Prepare compilation
$ ./configureBuild
$ makeInstall
$ make installOR if you don't want to overwrite the
pythonexecutable (safer, at least on some distrosyumneedspythonto be 2.x, such as for RHEL6) - you can installpython3.*as a concurrent instance to the system default with analtinstall:$ make altinstall
Now if you want an alternative installation directory, you can pass --prefix to the configurecommand.
Example: for 'installing' Python in /opt/local, just add --prefix=/opt/local.
After the make install step: In order to use your new Python installation, it could be, that you still have to add the [prefix]/bin to the $PATH and [prefix]/lib to the $LD_LIBRARY_PATH (depending of the --prefix you passed)