I have a fresh install of Debian 9.8, the current stable release version.
Python 3.7 is already in the raspbian buster repositories. It will not be in the raspbian stretch repositories. When the raspberry pi foundation switch their images from stretch to buster is up to them, but I would expect it to be some time around the time buster goes stable which I expect to be something around 4 months from now.
This system includes Python 3.5.3:
Unfortunately that version doesn't meet my needs. I want a more current version of Python. At the time of writing, the current version is 3.7.2.
Hopefully this will be helpful for a range of versions, but in the interest of limiting the scope to something we can be very precise about, this question is about the above combination of OS and python versions.
To further specify: I want to build from the python git source repository, using the default configuration: we'll run
./configure
with no arguments except maybe --prefix
to choose a custom install location. I want any needed dependencies to come from the standard Debian apt sources, if possible.Finally and most important: For any additional software we install as a prerequisite, give some information about it. Don't just say “install this incomprehensible list of apt packages”.
For any dependency available from Debian's stretch repositories, I want the following info:
- Whether the dependency can be considered optional or must be treated as required in order to successfully complete python's build/install steps.
- A link to the project homepage (or next next best thing if there isn't a suitable homepage, e.g. a repo url) that apt package came from.
- What feature/module in the resulting installation does the dependency map to? Sometimes this will be obvious because the names will be similar or identical between project name, package name, and the module it is used to build, but sometimes it won't.
With that kind of information, anyone reading this can have some understanding of what they are installing and why. The task of determining which dependencies their project will need will hopefully be made significantly easier.
CharlieCharlie
1 Answer
Install git
Install Python build dependencies
Python includes a set of modules that it builds by linking to other popular open source projects. Many of those projects are included in Debian by default as executable programs, but the development files (headers, libraries) necessary to link them into Python are packaged separately and not included in a default Debian install.
Some of these libraries are actually required for the python build/install steps to complete successfully:
The entries in the 'Dev Package' column are the names of packages containing the development files our python build needs.
Each of these 'dev' packages has a corresponding binary package that is probably already installed. So you're likely not going to be adding new pieces of software to your system by installing these. You're just installing the files necessary to compile new pieces of software (in our case a newer python) so that it can use them. (Also note that these 'dev' packages all have their corresponding binary packages asdependencies, so installing a dev package will ensure that its binary package is also installed.)
So let's install them:
Next we have the OpenSSL library. Python considers OpenSSL optional, but you probably want it. For example, even using Python's package installationtools can run into trouble when fetching
https
urls if SSL/TLS support is missing.Let's install it:
The next set of packages fall more in the 'optional' category:
![Raspberry Raspberry](/uploads/1/2/4/7/124794182/116668810.png)
Python can build and install without these, and your applications might not need them. On the other hand, if you install them, the 'make' step shouldn't report any modules it was unable to build, and the binaries are already included in a default Debian install.
The command to copy-paste if you'd like to go ahead and install all of the above 'optional' packages is:
Build and install python from source
- clone the python git repository.
- Checkout the version you want to install (in this case, 3.7.2) using the git tag name.
- Choose an install prefix. That is, the path the compiled and linked project will be installed into. In this case I'll use
$HOME/python/v3.7.2
. I'm including the version number since I'll want to install other versions in the future, and keep them separate. Run theconfigure
script with this path as the--prefix
argument. (If you don't provide a --prefix argument, it will default to/usr/local
).
The
configure
script will check a bunch of things, many of which are unnecessary. The ones shown in the above output, though, can be considered necessary.- Build python by running
make
. If we included the minimum set of dependencies necessary to build and install python, the output will tell you near the end what modules were not built:
The
make
output describes this as a list of 'optional' modules but again, at least for this particular version of python, it probably won't build and install successfully without the zlib
, and _ctypes
modules.- Install python by running
make install
. We've already provided the install location back in theconfigure
step. If your install location is a root-owned directory (e.g./usr/local
), prefix this command withsudo
. Since in this case I'm installing to a user-owned directory, I don't want to do that.
- You should now have an executable you can run from the
bin
directory underneath the install prefix namedpython3
. (Note that this installer doesn't put anything atbin/python
; justbin/python3
.)
CharlieCharlie