Lesson 16 of 19 ↓
- 1.Fedora + Distrobox + Arch + AUR Setup Guide
- 2.Enabling Hibernate on Linux
- 3.A Practical Git Workflow
- 4.Useful Linux Commands & Tips
- 5.Mirroring Your Android Screen with Scrcpy
- 6.Downloading Media with Yt-dlp
- 7.Consistent C/c++ Style with Clang-format
- 8.Auto-mounting Drives at Boot
- 9.Customizing Grub
- 10.Linux Swap Files Explained
- 11.Zram: Compressed Swap in Ram
- 12.Custom App Launch Behavior Via .desktop Files
- 13.Custom Mime Icons in Gnome
- 14.Fixing Missing Dock Icons (startupwmclass)
- 15.Installing Questasim for Hdl Simulation
- 16.Building Python 2 From Source
- 17.Auto-Starting WhatsApp and Telegram (Minimized or Tray)
- 18.Custom Neovim Configuration Guide
- 19.Running Windows Applications on Linux Seamlessly with WinBoat (Docker)
1 min read
Building Python 2 From Source
linux
Some older tools — QuestaSim's license generator among them — still hard-depend on Python 2, which modern distros no longer package. Building it from source into an isolated location keeps it fully separate from the system Python.
Install Build Dependencies
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev \
libnss3-dev libssl-dev libreadline-dev libffi-dev wgetDownload and Extract the Source
cd ~/Downloads
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar -xf Python-2.7.18.tgz
cd Python-2.7.18Build Into a Private Prefix
Installing to a custom prefix (rather than system-wide) means it never conflicts with anything the OS expects Python to be:
./configure --prefix=$HOME/myApps/python2 --enable-optimizations
make
make installAlias python2
nano ~/.bashrcAdd:
alias python2='$HOME/myApps/python2/bin/python'source ~/.bashrc
python2 --version # Python 2.7.18Alternative: a Virtual Environment
If several tools need Python 2, a virtualenv keeps them isolated from each other too:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2 get-pip.py
python2 -m pip install virtualenv
$HOME/myApps/python2/bin/virtualenv ~/myApps/python_env/python2_envActivate/deactivate as usual:
source ~/myApps/python_env/python2_env/bin/activate
python -V # Python 2.7.18
deactivateThe environment persists on disk, so it can be re-activated any time with the same source command without rebuilding anything.
Comments
Loading the discussion…