Instantly share code, notes, and snippets.

What would you like to do?
Building Python on the Raspberry Pi2
# Condensed and revised from Blake's site (unreachable currently):
# Install prerequisites
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y \
build-essential libncursesw5-dev libgdbm-dev libc6-dev \
zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl \
libreadline6-dev liblzma-dev libbz2-dev libdb-dev
# Perhaps libreadline-dev will just as well above
# Choose a version:
# Set version (3.4)
export MYPYMAJ=3
export MYPYMIN=4
export MYPYPNT=3
# Set version (3.5)
export MYPYMAJ=3
export MYPYMIN=5
export MYPYPNT=1
# Set version (2.7)
export MYPYMAJ=2
export MYPYMIN=7
export MYPYPNT=11
# Get sources and build locally
mkdir -p ~/Projects
cd ~/Projects
wget --continue${MYPYVER}/Python-${MYPYVER}.tgz
tar -zxvf Python-${MYPYVER}.tgz
cd Python-${MYPYVER}
make -j 4
# Install any missing deps and run 'make' again.
# For the completists:
# Python 2.7 will warn about 'sunaudiodev' - ignore it:
# Likewise the ancient 'bsddb185' apparently can be ignored as well
# Alt install so we don't clobber the system's Python version!
# But whyyyyyy?
# Details:
# But, note that while 'python2' will still refer to the system's Python 2.7, 'python2.7' will now refer to yours!
# Presumably the same would be true for Python 3.2 were you to altinstall that.
# Pip will be similarly affected.
sudo make altinstall
# Test the Python you installed
# Check if Pip works already
pip${MYPYREL} --version
# If not, get Pip (superfluous anymore...)
cd ~/Projects
sudo python${MYPYREL}
pip${MYPYREL} --version

This comment has been minimized.


MartyMacGyver commented May 21, 2017

I've learned that gist has a major old bug wherein you don't get notifications for comments to gists.

If you leave a comment, it would be appreciated if you ping me elsewhere so I know to find it!

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