Skip to content

Instantly share code, notes, and snippets.

@materro
Last active July 5, 2024 01:55
Show Gist options
  • Select an option

  • Save materro/6b2b0a0ed541da88dd04dcd4902605db to your computer and use it in GitHub Desktop.

Select an option

Save materro/6b2b0a0ed541da88dd04dcd4902605db to your computer and use it in GitHub Desktop.
Install Python 3.11 from source in local directory on Ubuntu Precise

Install Python 3.11 in local directory on Ubuntu Precise

I needed to install the latest version of Python on an old version of Ubuntu. I succeeded 😊 Below I've written out the instructions on how I realized it.

Dependencies

Run every command as root πŸ”₯

Install required dependencies

apt-get install libffi-dev libgdbm-dev libreadline6-dev liblzma-dev

Install newer gcc and g++

cd /usr/src
wget https://ftp.man.poznan.pl/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.gz
tar xf gcc-7.5.0.tar.gz
cd gcc-7.5.0/
./contrib/download_prerequisites --no-verify
cd ../
mkdir gcc-7.5.0-build && cd gcc-7.5.0-build
../gcc-7.5.0/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-7.5 --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-7.5
make -j4
make install

Setup environment after installing:

export PATH=/usr/local/gcc-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/gcc-7.5/lib64:$LD_LIBRARY_PATH

Link gcc and g++ to newer version

cd /usr/bin
rm gcc
ln -s /usr/local/gcc-7.5/bin/gcc
rm g++
cp /usr/local/gcc-7.5/bin/g++-7.5 g++

g++ --version should output g++ (GCC) 7.5.0 and gcc --version should output gcc (GCC) 7.5.0.

Install SQLite

cd /usr/src
wget https://www.sqlite.org/2022/sqlite-autoconf-3400000.tar.gz
tar xfz sqlite-autoconf-3400000.tar.gz
cd sqlite-autoconf-3400000
./configure --prefix=/usr/local/sqlite
make
make install

Install TK/TCL

cd /usr/src
wget http://prdownloads.sourceforge.net/tcl/tcl8.6.13-src.tar.gz
tar xfz tcl8.6.13-src.tar.gz
cd tcl8.6.13
./configure --prefix=/usr/local
make
make install
wget http://prdownloads.sourceforge.net/tcl/tk8.6.13-src.tar.gz
tar xfz tk8.6.13-src.tar.gz
cd tk8.6.13
./configure --prefix=/usr/local
make
make install

Optionally install OpenSSL

cd /usr/src
wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz
tar xzf openssl-1.1.1s.tar.gz
cd openssl-1.1.1s
./config --prefix=/usr/local/src-openssl-1.1.1s --openssldir=/usr/local/src-openssl-1.1.1s
make
make install

Finally install Python 3.11 😻

Use /usr/local TK/TCL, SQLite and OpenSSL localizations πŸ‘

cd /usr/src
wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
tar xzf Python-3.11.1.tgz
cd Python-3.11.1
CPPFLAGS="${CPPFLAGS} -I/usr/local/include -I /usr/local/sqlite/include" LDFLAGS="${LDFLAGS} -Wl,-rpath=/usr/local/src-openssl-1.1.1s/lib -Wl,-rpath=/usr/local/sqlite/lib -Wl,-rpath=/usr/local/lib/tk8.6 -Wl,-rpath=/usr/local/lib/tcl8.6" ./configure --enable-optimizations --with-openssl=/usr/local/src-openssl-1.1.1s --with-pydebug
make altinstall

Check installed version πŸ”₯

python3.11 -V
pip3.11 --version

Alternatively link 3.11 as main version:

cd /usr/bin
rm python
ln -s /usr/local/bin/python3.11 python
rm pip
ln -s /usr/local/bin/pip3.11 pip

Enjoy 😊

@devbeno

devbeno commented Jul 5, 2024

Copy link
Copy Markdown

For ubuntu 20.04

cd /usr/src
wget http://prdownloads.sourceforge.net/tcl/tcl8.6.13-src.tar.gz
tar xfz tcl8.6.13-src.tar.gz
cd tcl8.6.13/unix
./configure --prefix=/usr/local
make
sudo make install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment