-
Notifications
You must be signed in to change notification settings - Fork 2
Python
Even the Raspberry Pi folks consider Python 2 to be legacy. The least we can do is upgrade it to a newer version of 2 and 3. These instructions show how to do it.
Check to see if you've installed the following packages first.
$ sudo apt-get install build-essential libc6-dev openssl zlib1g-dev
As of the Feburary 2016 update, all those packages are installed.
If you have, don't download them. DO however download the next set of packages. These weren't installed.
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install libncursesw5-dev libgdbm-dev libsqlite3-dev tk-dev libssl-dev libreadline-dev
This will also install
libfontconfig1-dev libice-dev libpthread-stubs0-dev libsm-dev libssl-doc libtinfo-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev tcl tcl-dev tcl8.6 tcl8.6-dev tk tk8.6-dev x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-render-dev x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev
I think there may be a spelling error somewhere, but whatever is in this list, let apt-get download those too!
⚠️ IMPORTANT! If you want to use the up and down arrow keys in the python prompt to scroll back to a previous line, you must havelibreadline-devinstalled, or else arrow keys will not process when python is compiled.
We'll do this for Python 2 and 3.
:note: NOTE: If you plan on installing GNU Radio, don't install these local Pythons until AFTER. If you didn't follow this instruction, it's OK. This blockquote warning is more of an advisory rather than a recommendation. Still, the GNU Radio guys haven't gotten with the program yet by using Python 3.
$ cd ~/Software
$ curl -SL https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz | tar xJv
$ curl -SL https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz | tar xJv
$ cd Python-2.7.11
$ ./configure && make -j4 && sudo make install
$ cd ..
$ cd Python-3.5.1
$ ./configure && make -j4 && sudo make install
We may need to add a file to /etc/profile.d/ especially if you don't install Python in /usr/local. I'll discuss that in the GQRX article where it is more relevant.
Take notice in these three tests to see if everything is running.
$ python
Python 2.7.11 (default, Feb 25 2016, 00:53:12)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python3
Python 3.5.1 (default, Feb 25 2016, 01:27:36)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python3.5
Python 3.5.1 (default, Feb 25 2016, 01:27:36)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$
Basically the best way to call Python 2 is still python. For Python 3, use python3.5. Ergo, the first line of any Python 2 script should be !/usr/local/bin/python and any python 3 script should probably be !/usr/local/bin/python3.5.
🆙 UPDATE: If you followed the instructions from the "Download and Make" section and it looks like it does in the "Test Everything" section, you don't need to do this. Ignore this section.
You shouldn't have to. Here's why.
$ which python
/usr/local/bin/python
$ which python2
/usr/local/bin/python2
$ which python2.7
/usr/local/bin/python2.7
$ which python3
/usr/local/bin/python3
$ which python3.5
/usr/local/bin/python3.5
$ ls /usr/local/bin/py* | sed -n -e 's/.*:[0-5][0-9] \(.*\)/\1/gp'
/usr/local/bin/py
/usr/local/bin/pydoc3 -> pydoc3.5
/usr/local/bin/pydoc3.5
/usr/local/bin/python -> python2
/usr/local/bin/python2 -> python2.7
/usr/local/bin/python2.7
/usr/local/bin/python2.7-config
/usr/local/bin/python2-config -> python2.7-config
/usr/local/bin/python3 -> python3.5
/usr/local/bin/python3.5
/usr/local/bin/python3.5-config -> python3.5m-config
/usr/local/bin/python3.5m
/usr/local/bin/python3.5m-config
/usr/local/bin/python3-config -> python3.5-config
/usr/local/bin/python-config -> python2-config
/usr/local/bin/pyvenv -> pyvenv-3.5
/usr/local/bin/pyvenv3.5
From the list of files, we can confirm that the default version of Python is now the version that we installed.
Although, if we wanted to, which I'm not completely sold on the idea at the moment, we could use update-alternatives to redirect python to the /usr/local versions we just installed. But there is a /usr/bin/pip3 which would conflict with /usr/local/bin/pip3, and neither of them are softlinks, which is the intent of update-alternatives, to make softlinks that point to the primary version of the software we want to use. This worked for [Java] and would likely work for [Ruby]. If we could do this, the process would look like this.
⚠️ NEVER MAKE PYTHON 3 YOUR DEFAULT PYTHON! As much as we want Guido to finally kill off Python 2, setting yourupdate-alternativesshortcuts forpythontopython3will break a ton of stuff. THIS IS THEORETICAL CODE! DON'T DO IT UNLESS YOU ARE ABSOLUTELY SURE YOU TO BREAK STUFF!
$ sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python 0
$ sudo update-alternatives --install /usr/bin/python-config python-config /usr/local/bin/python-config 0
$ sudo update-alternatives --install /usr/bin/python2 python2 /usr/local/bin/python2 0
$ sudo update-alternatives --install /usr/bin/python2-config python2-config /usr/local/bin/python2-config 0
$ sudo update-alternatives --install /usr/bin/python2.7 python2.7 /usr/local/bin/python2.7 0
$ sudo update-alternatives --install /usr/bin/python2.7-config python2.7-config /usr/local/bin/python2.7-config 0
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3 0
$ sudo update-alternatives --install /usr/bin/python3-config python3-config /usr/local/bin/python-config3 0
$ sudo update-alternatives --install /usr/bin/python3.5 python3.5 /usr/local/bin/python3.5 0
$ sudo update-alternatives --install /usr/bin/python3.5-config python3.5-config /usr/local/bin/python-config3.5 0
$ sudo update-alternatives --install /usr/bin/python3.5m python3.5m /usr/local/bin/python3.5m 0
$ sudo update-alternatives --install /usr/bin/python3.5m-config python3.5m-config /usr/local/bin/python-config3.5m 0
$ sudo update-alternatives --install /usr/bin/pydoc pydoc /usr/local/bin/pydoc 0
$ sudo update-alternatives --install /usr/bin/pydoc3 pydoc3 /usr/local/bin/pydoc3 0
$ sudo update-alternatives --install /usr/bin/pydoc3.5 pydoc3.5 /usr/local/bin/pydoc3.5 0
$ sudo update-alternatives --install /usr/bin/pyenv pyenv /usr/local/bin/pyenv 0
$ sudo update-alternatives --install /usr/bin/pyenv-3.5 pyenv-3.5 /usr/local/bin/pyenv-3.5 0
Much like Ruby gem, Python uses pip. Ideally, any software you install for Python should be done this way. Check out PyPi for packages.
pip is included with python as of Python 2 >=2.7.9 and Python 3 >=3.4 downloaded from python.org, but you'll need to upgrade pip.
$ sudo pip3 install -U pip
$ sudo pip install -U pip # this likely won't do anything because this pip came with Raspbian (`pip in /usr/local/lib/python2.7/dist-packages`)
$ sudo pip3 install -U pip # this will do something because this pip was user-installed (`pip in /usr/local/lib/python3.5/site-packages`)
To see what was installed or upgraded for pip chekc out /usr/local/lib/python3.5/.
Python 3. A lot of code is still written in Python 2 which is why we have both versions installed, but to truly get rid of Python 2, we need people to start using Python 3. Python 3 won't have this problem if a Python 4 ever comes out.
While other languages can work with GPIO, especially Ruby and Node, Raspberry Pi likes Python.
- https://www.raspberrypi.org/documentation/usage/python/more.md
- https://www.python.org/downloads/
- https://pypi.python.org/pypi
- http://sowingseasons.com/blog/building-python-2-7-10-on-raspberry-pi-2.html
- http://sowingseasons.com/blog/building-python-3-4-on-raspberry-pi-2.html
- https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Setup
- [Assemble the Hardware](Assemble the Hardware)
- [Install the Software](Install the Software)
- SD Card Formatting and Image Mounting
- ❤️ [TLDR version](Install the Software#tldr)
- 🆕 [Windows version](Install the Software#doing-this-in-windows)
- 🆙 [Setup your Raspberry Pi](Setup your Raspberry Pi)
- [Download the Missing Parts](Download the Missing Parts)
- Clone this repo
- 🆕 [Install these first](Install these first)
-
Python(It's taken care of) - 🆙 CMake
- 🆙 Node
- 🆕 Expect (Tcl/Tk is not dead!)
- 🆙 tmux and ncurses
- 🆙 htop
- 🆙 wavemon
- Vim
- 🆙 Ruby
- 🆙 weechat
- 🆕 urxvt 256 color terminal!
- 🆕 i3 A better window manager
- 🆕 Ranger
- 🆙 Qt5
- 🆕 Chromium
wicd-curses- 📻 Software Defined Radio
- 🎮 [Linux Toys](Linux Toys)
Typical Utilities
- [Downloading and extracting with curl and tar](curl and tar)
- [Browsing with ls and cat](ls and cat)
- [Searching with grep and find](grep and find)
- [Filtering with sed and awk](sed and awk)
- [Piping with less, pv, and tee](less, pv, and tee)
- Monitor your system with htop
- Multiplex with tmux