Install newest Python as a normal user

Sometimes you and not the root user or admin, but you cannot fed up with the outdated python environment like Python3.6 or Python3.7. I tried to find out a solution, as a matter of fact, it is not difficult to do, we presume that one wants to install the python environment in on a Linux based server where you are don’t have the administrator access and the off the shelf python environment is too old or you want to install your own pip modules.

You could check out the version of the installed python environment by the following commands and observe the returned value:

[user@ssh ~]$ python --version
Python 2.7.5
[user@ssh ~]$ python3 --version
Python 3.6.8

I referred to this education institution link, even through it describes how to install python2, the main steps still works for python3. Here it is.

Download the python zip file, for the latest python3.11, you could use the wget command line tool, please go to the link to check for the latest or your preferred python version.

wget https://www.python.org/ftp/python/3.11.5/Python-3.11.5.tar.xz

The archive is now with extension tar.xz, so one has to unzip it with another tool than tar, but this is not going to be a problem.

tar -xvf Python-3.11.5.tar.xz

Setup the directory for the compiled python directory, it should be inside your folder since you don’t have sudo rights.

mkdir ~/Utilities/Python3

One thing that is important is to setup the building environment: ./configure {python_dir}, this command enables the compilation should be placed inside the python directory in your home folder. In this step, it is going to check the whole environment of the system, tools for compilation, libraries that would be used. So there could be chance that your OS is not able to compile correctly.

./configure --prefix="~/Utilities/Python3"

Then type: make -j, -j stands for use multiple cores.

make -j

If things goes well: make install, it is going to put compiled python executables to the directory, please also put the directory to $PATH environment.

I believe that is it, you VS code is able to find out your shiny new python intepreter. Final thoughts, it just feels like compiling a c probject and it is, you can ask chatgpt to write a python script for you to streamline the whole process, it could be useful somtimes. But most of the time, you would have admin rights to install with package manager.


Posted

in

by

Tags:

Comments

One response to “Install newest Python as a normal user”

Leave a Reply

Your email address will not be published. Required fields are marked *