Search code examples
pythonpython-3.xlinuxopensuse

Install python on Linux from source with custom paths


I found tutorials how to install it from source, but in all of them the default config is used.

I want to install a new python version, on a different partition than the one where the operating system is, so not in /usr/bin and default paths.

So, in case I revert my main partition from backup, to not be necessary to re-install the new python version. Also to be easy(small changes) to (re)direct an IDE like VisualStudioCode or Pycharm to the new python version.(just add to path maybe).

I prefer not to install a tool to do that.


Solution

  • The process is quite straight forward, let's say you want to install in your $HOME

    # 0) Download python source and extracted it to $HOME/tmp/Python3.9.2 directory
    # 1)
    mkdir $HOME/usr
    # 2)
    cd $HOME/tmp/Python3.9.2
    # 3)
    ./configure --prefix=$HOME/usr && make
    # 4) Now python is built in $HOME/tmp/Python3.9.2, give it a test, then
    make install
    # Now you should have $HOME/usr/bin/python ready to use.