Skip to content

Instantly share code, notes, and snippets.

@xslendix
Last active July 15, 2021 17:34
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save xslendix/fcb55ae06b49be557e3418cfa8af4534 to your computer and use it in GitHub Desktop.
Save xslendix/fcb55ae06b49be557e3418cfa8af4534 to your computer and use it in GitHub Desktop.
Install python 3.6 on your RPi!
#!/usr/bin/bash
putsc() {
echo -en "\e[34m :: \e[0m $@"
}
putscl() {
putsc "$@\n"
}
cores="$(ncores)"
putscl "Which Python version do you wish to download? (3.6.0, 3.6.4 etc.) "
read version
putscl Updating system.
sudo apt update
sudo apt upgrade
putscl Installing required build dependencies.
sudo apt install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev -y
putscl Downloading Python $version source code.
pushd
mkdir -p $HOME/.local/src
cd $HOME/.local/src
wget https://www.python.org/ftp/python/$version/Python-$version.tar.xz
tar xvf Python-$version.tar.xz
cd Python-$version
putscl Configuring.
./configure
putscl Compiling.
make -j$cores
putscl Installing.
sudo make altinstall
putsc "Installation done! Do you wish to delete the source code? [Y/n] "
read ans
if [[ ans == [Yy]* ]]
then
sudo rm -r Python-$version
rm Python-$version.tar.xz
sudo apt autoremove
sudo apt clean
fi
popd
putscl "Done! Python should now be installed in `/usr/local/bin/python$version`!"
Copy link

ghost commented Feb 11, 2018

Any reason not to be using 3.6.4?

Merely curious, as if there is a genuine reason, it would be awesome to know about.

Also, you probably want to run make -j4, otherwise you will be waiting a lot longer to get the build to finish :)

Copy link

ghost commented May 6, 2018

Hello

@SeppPenner
Copy link

Just one thing: You are downloading Python-3.6.0.tar.xz and removing Python-3.6.0.tgz. This will not work! Line 15 should be

rm Python-3.6.0.tar.xz

@SeppPenner
Copy link

I have scripts for 3.6.0, 3.6.4 and 3.7.0 done. Take a look at them, too. They should be working.

@Zacharyprime
Copy link

This is just my opinion, but build-essential is something every linux machine should have so it might not be great to remove it since most will have had it before install.

@xslendix
Copy link
Author

xslendix commented Jul 15, 2021

build-essential is used for gcc, make, header files and other stuff required for development. Here it's used to compile py 3.6.0

@xslendix
Copy link
Author

I get your point, I don't understand why previous me had that in the script, maybe to remove bloat if you dont need it? Doesn't matter though since you can just say N

@xslendix
Copy link
Author

xslendix commented Jul 15, 2021

Updated the script to make the output nicer and fixed some bugs.

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