I wanted to install the latest Python on Linux in a low powered user’s home directory and not have the install interfere with the Python that comes with Linux. I wanted my own local copy of Python that I could install Python packages to without interfering with anything else. I was willing to use root to install the needed Linux packages, but everything else was done with my low powered user.
I did a yum update on my Oracle Enterprise Linux 7.7 install before I started to get everything on the latest version. As root I used yum to install the Linux packages I needed to install Python 3.8.1 from source:
I must have already installed these on this VM. I did the rest of these steps as my low powered user “bobby”. The next thing I did was download the latest Python source, the 3.8.1 version. I had to use the -k option to get around certificate issues:
[bobby@pythonvm ~]$ curl -k -O https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 22.8M 100 22.8M 0 0 7830k 0 0:00:02 0:00:02 --:--:-- 7828k
For some reason I had to do this twice. The first download failed. Next I gunzipped and untarred this archive under my home directory:
tar zxfv Python-3.8.1.tgz Python-3.8.1/Objects/sliceobject.c Python-3.8.1/Objects/listobject.c Python-3.8.1/Objects/typeslots.inc Python-3.8.1/Objects/weakrefobject.c Python-3.8.1/Objects/unicodeobject.c Python-3.8.1/Objects/complexobject.c Python-3.8.1/Objects/picklebufobject.c Python-3.8.1/Objects/odictobject.c Python-3.8.1/Objects/genobject.c [bobby@pythonvm ~]$
I created a directory called “python” under my home directory to use as the top-level directory for my Python install. This directory tree will hold the binaries and any Python packages that I install.
[bobby@pythonvm ~]$ mkdir python
After changing directory to where I untarred the source files I configured the Python make and install to use the directory I just created as a “prefix”:
[bobby@pythonvm ~]$ cd Python-3.8.1 [bobby@pythonvm Python-3.8.1]$ pwd /home/bobby/Python-3.8.1 ./configure --prefix=/home/bobby/python config.status: creating Misc/python-embed.pc config.status: creating Misc/python-config.sh config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h creating Modules/Setup.local creating Makefile If you want a release build with all stable optimizations active (PGO, etc), please run ./configure --enable-optimizations
Then I did the make and make altinstall from the same directory:
So, now Python 3.8.1 is installed in /home/bobby/python but I want to put the bin directory in the path so I can run python or pip and by default have them be this version. The install created python and pip as python3.8 and pip3.8 but I created links to them so that I could access them without 3.8 at the end of their names:
[bobby@pythonvm Python-3.8.1]$ cd /home/bobby/python/bin [bobby@pythonvm bin]$ ls -al total 16704 drwxr-xr-x. 2 bobby bobby 4096 Feb 10 15:36 . drwxrwxr-x. 6 bobby bobby 52 Feb 10 15:36 .. -rwxrwxr-x. 1 bobby bobby 109 Feb 10 15:36 2to3-3.8 -rwxrwxr-x. 1 bobby bobby 249 Feb 10 15:36 easy_install-3.8 -rwxrwxr-x. 1 bobby bobby 107 Feb 10 15:36 idle3.8 -rwxrwxr-x. 1 bobby bobby 231 Feb 10 15:36 pip3.8 -rwxrwxr-x. 1 bobby bobby 92 Feb 10 15:36 pydoc3.8 -rwxr-xr-x. 1 bobby bobby 17075312 Feb 10 15:35 python3.8 -rwxr-xr-x. 1 bobby bobby 3095 Feb 10 15:36 python3.8-config [bobby@pythonvm bin]$ ln -s python3.8 python [bobby@pythonvm bin]$ ln -s pip3.8 pip
Then I added/home/bobby/python/bin to the front of the path to keep these new python and pip links ahead of the python links or binaries in the rest of the path.
[bobby@pythonvm bin]$ cd [bobby@pythonvm ~]$ vi .bashrc export ORACLE_HOME=/home/oracle/app/oracle/product/12.1.0/client_1 export PATH=$PATH:$ORACLE_HOME/bin export LD_LIBRARY_PATH=/home/oracle/app/oracle/product/12.1.0/client_1/lib export PATH=/home/bobby/python/bin:$PATH ~ ~ ~ ~ ~ ~ ".bashrc" 17L, 451C written
I logged out and in as bobby and tried python and pip to see that they were the correct version:
[bobby@pythonvm ~]$ python Python 3.8.1 (default, Feb 10 2020, 15:33:01) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39.0.3)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> [bobby@pythonvm ~]$ pip list Package Version ---------- ------- pip 19.2.3 setuptools 41.2.0 WARNING: You are using pip version 19.2.3, however version 20.0.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. [bobby@pythonvm ~]$
Finally, I updated pip just to show that we can update something in this new install. Then I installed numpy to see if I could install a new package.
This is a quick and dirty post, but I want to remember these steps for myself and it might be helpful for someone who uses Redhat/Centos/OEL.