Python 3.6 is broken

I need python 3.6 and have tried resin/raspberrypi3-python:3.6 but this still installs python 3.4.
I see the image is based on jessie which has python3.4.
Upgrading pip results in lots of errors - I think this is a bug.

any ideas?

I just tried the image and it’s at version 3.6.4

root@b5f2b2138619:/# python --version
Python 3.6.4

Can you please send us your Dockerfile since we use python binary built from source instead of Python package from Debian distribution so maybe something in your Dockerfile causes this issue?

and python --version reports 3.6.4 as well

I am posting this in a number of separatye parts as there is a limit:

Here is the Dockerfile:

phewlett@phewlett-XPS-15-9560:~/electronrx/git/ebio/button-gateway change-resin-image $ cat Dockerfile.template 
# base-image for python on any machine using a template variable,
# see more about dockerfile templates here: http://docs.resin.io/deployment/docker-templates/
# and about resin base images here: http://docs.resin.io/runtime/resin-base-images/
# docker pull armhf/ubuntu

# FROM arm32v7/ubuntu:artful
# FROM resin/armv7hf-debian:stretch
FROM resin/raspberrypi3-python:3.6

ENV DBUS_SYSTEM_BUS_ADDRESS unix:path=/host/run/dbus/system_bus_socket

# define our working directory in the container
WORKDIR usr/src/app

ENV PYTHON_CONFIG=/usr/src/app/config.yaml

# copy all files in our root to the working directory
COPY . ./

# Build everything
RUN ./buildscripts/build.sh

# enable systemd init system in the container  
# disabled as application failure should cause container to restart
ENV INITSYSTEM on

# execute in shell
 CMD ["bash", "start.sh"]

build.sh is:

#!/bin/sh -ex
#
# build everything
#
ls -l /etc/*release
cat /etc/*release
python --version
# bluez requires python3-gi, python-gi-cairo, python-dbus, gir1.2-gtk-3.0
# grpcio requires python3-dev
#
apt-get update && apt-get install -yq --no-install-recommends \
    bluez \
    ca-certificates \
    gcc \
    gir1.2-gtk-3.0 \
    libdpkg-perl \
    python3-dbus \
    python3-dev \
    python3-gi \
    python3-gi-cairo \
    python3-pip \
    vim \
 && apt-get -y autoremove \
 && apt-get -y autoclean \
 && apt-get -y clean \
 && rm -rf /var/lib/apt/lists/*

PIP_CONFIG_FILE=~/.config/pip/pip.conf

pip3 install --upgrade --ignore-installed pip setuptools

# Overwrite bluetooth config files
cp bluetooth.init /etc/init.d/bluetooth
cp defaults.bluetooth /etc/default/bluetooth

# install python pure dependencies
pip3 install -r ./requirements-dev.txt
pip3 install -r ./requirements.txt

# Static code analysis
pycodestyle --show-pep8 button_gateway tests
python3 -m pylint --rcfile=pylintrc button_gateway tests

# Remove static tools
pip3 uninstall -y -r ./requirements-dev.txt

# Remove all build artifacts
apt-get remove -yq \
    gcc \
    libdpkg-perl \
    python3-dev \
    python3-pip \
 && apt-get -y autoremove \
 && apt-get -y autoclean \
 && apt-get -y clean \
 && rm -rf /var/lib/apt/lists/*

Log output shows (redacted):

+ find -name __pycache__ -delete -print
+ git symbolic-ref --short HEAD
+ BRANCH=change-resin-image
+ [ -n change-resin-image ]
+ git push -f resin change-resin-image:master
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 901 bytes | 901.00 KiB/s, done.
Total 7 (delta 4), reused 0 (delta 0)

[Info]     Starting build for bluetoothrelay, user g_bryn_mathias
[Info]     Dashboard link: https://dashboard.resin.io/apps/960459/devices
[Info]     Building on arm03
[Info]     Pulling previous images for caching purposes...
[Success]  Successfully pulled cache images
[gateway]  Step 1/8 : FROM resin/raspberrypi3-python:3.6
[gateway]   ---> c1c02e739ada
[gateway]  Step 2/8 : ENV DBUS_SYSTEM_BUS_ADDRESS unix:path=/host/run/dbus/system_bus_socket
[gateway]  Using cache
[gateway]   ---> dfc65152aa0e
[gateway]  Step 3/8 : WORKDIR usr/src/app
[gateway]  Using cache
[gateway]   ---> 78a5fbd8a681
[gateway]  Step 4/8 : ENV PYTHON_CONFIG /usr/src/app/config.yaml
[gateway]  Using cache
[gateway]   ---> a885ed84d2b3
[gateway]  Step 5/8 : COPY . ./
[gateway]  Using cache
[gateway]   ---> f696463cbb8a
[gateway]  Step 6/8 : RUN ./buildscripts/build.sh
[gateway]   ---> Running in ced33db1e31d
[gateway]  + ls -l /etc/os-release
[gateway]  
[gateway]  lrwxrwxrwx 1 root root 21 Dec  4 15:12 /etc/os-release -> ../usr/lib/os-release
[gateway]  + cat /etc/os-release
[gateway]  
[gateway]  PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
[gateway]  NAME="Debian GNU/Linux"
[gateway]  VERSION_ID="8"
[gateway]  VERSION="8 (jessie)"
[gateway]  ID=debian
[gateway]  HOME_URL="http://www.debian.org/"
[gateway]  SUPPORT_URL="http://www.debian.org/support"
[gateway]  BUG_REPORT_URL="https://bugs.debian.org/"
[gateway]  + python --version
[gateway]  
[gateway]  Python 3.6.4
[gateway]  + apt-get update
[gateway]  
[gateway]  Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
[gateway]  Get:2 http://archive.raspbian.org jessie InRelease [14.9 kB]
[gateway]  Get:3 http://archive.raspberrypi.org jessie InRelease [22.9 kB]
[gateway]  Ign http://deb.debian.org jessie InRelease
[gateway]  Get:4 http://deb.debian.org jessie-updates InRelease [145 kB]
[gateway]  Get:5 http://deb.debian.org jessie Release.gpg [2434 B]
[gateway]  Get:6 http://deb.debian.org jessie Release [148 kB]
[gateway]  Get:7 http://security.debian.org jessie/updates/main armhf Packages [615 kB]
[gateway]  Get:8 http://archive.raspbian.org jessie/main armhf Packages [13.3 MB]
[gateway]  Get:9 http://archive.raspberrypi.org jessie/main armhf Packages [172 kB]
[gateway]  Get:10 http://deb.debian.org jessie-updates/main armhf Packages [23.1 kB]
[gateway]  Get:11 http://deb.debian.org jessie/main armhf Packages [8864 kB]
[gateway]  Get:12 http://archive.raspbian.org jessie/contrib armhf Packages [49.5 kB]
[gateway]  Get:13 http://archive.raspbian.org jessie/non-free armhf Packages [101 kB]
[gateway]  Get:14 http://archive.raspbian.org jessie/rpi armhf Packages [1297 B]
[gateway]  Get:15 http://archive.raspbian.org jessie/firmware armhf Packages [1202 B]
[gateway]  Fetched 23.5 MB in 12s (1962 kB/s)
[gateway]  Reading package lists...
[gateway]  + apt-get install -yq --no-install-recommends bluez ca-certificates gcc gir1.2-gtk-3.0 libdpkg-perl python3-dbus python3-dev python3-gi python3-gi-cairo python3-pip vim
[gateway]  
[gateway]  Reading package lists...
[gateway]  Building dependency tree...
[gateway]  Reading state information...
[gateway]  ca-certificates is already the newest version.
[gateway]  libdpkg-perl is already the newest version.
[gateway]  libdpkg-perl set to manually installed.
[gateway]  gcc is already the newest version.
[gateway]  gcc set to manually installed.
[gateway]  The following extra packages will be installed:
[gateway]    adwaita-icon-theme dbus dconf-gsettings-backend dconf-service dh-python
[gateway]    gir1.2-atk-1.0 gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-glib-2.0
[gateway]    gir1.2-pango-1.0 glib-networking glib-networking-common
[gateway]    glib-networking-services gsettings-desktop-schemas init-system-helpers
[gateway]    libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3
[gateway]    libavahi-common-data libavahi-common3 libcairo-gobject2 libcap-ng0
[gateway]    libcolord2 libcups2 libdconf1 libexpat1-dev libgirepository-1.0-1 libgpm2
[gateway]    libgtk-3-0 libgtk-3-bin libgtk-3-common libjson-glib-1.0-0
[gateway]    libjson-glib-1.0-common libmpdec2 libpangoxft-1.0-0 libproxy1 libpython3-dev
[gateway]    libpython3-stdlib libpython3.4 libpython3.4-dev libpython3.4-minimal
[gateway]    libpython3.4-stdlib librest-0.7-0 libsoup-gnome2.4-1 libsoup2.4-1
[gateway]    libwayland-client0 libwayland-cursor0 libxcomposite1 libxcursor1 libxdamage1
[gateway]    libxfixes3 libxft2 libxi6 libxinerama1 libxkbcommon0 libxrandr2 python3
[gateway]    python3-cairo python3-chardet python3-colorama python3-distlib
[gateway]    python3-html5lib python3-minimal python3-pkg-resources python3-requests
[gateway]    python3-setuptools python3-six python3-urllib3 python3.4 python3.4-dev
[gateway]    python3.4-minimal vim-common vim-runtime xkb-data
[gateway]  Suggested packages:
[gateway]    dbus-x11 cups-common gpm gvfs python3-doc python3-tk python3-venv
[gateway]    python-dbus-doc python3-dbus-dbg python3-genshi python3-lxml
[gateway]    python3-ndg-httpsclient python3-openssl python3-pyasn1 python3.4-venv
[gateway]    python3.4-doc binfmt-support ctags vim-doc vim-scripts
[gateway]  Recommended packages:
[gateway]    at-spi2-core colord python3-wheel
[gateway]  The following NEW packages will be installed:
[gateway]    adwaita-icon-theme bluez dbus dconf-gsettings-backend dconf-service
[gateway]    dh-python gir1.2-atk-1.0 gir1.2-freedesktop gir1.2-gdkpixbuf-2.0
[gateway]    gir1.2-glib-2.0 gir1.2-gtk-3.0 gir1.2-pango-1.0 glib-networking
[gateway]    glib-networking-common glib-networking-services gsettings-desktop-schemas
[gateway]    init-system-helpers libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data
[gateway]    libatspi2.0-0 libavahi-client3 libavahi-common-data libavahi-common3
[gateway]    libcairo-gobject2 libcap-ng0 libcolord2 libcups2 libdconf1 libexpat1-dev
[gateway]    libgirepository-1.0-1 libgpm2 libgtk-3-0 libgtk-3-bin libgtk-3-common
[gateway]    libjson-glib-1.0-0 libjson-glib-1.0-common libmpdec2 libpangoxft-1.0-0
[gateway]    libproxy1 libpython3-dev libpython3-stdlib libpython3.4 libpython3.4-dev
[gateway]    libpython3.4-minimal libpython3.4-stdlib librest-0.7-0 libsoup-gnome2.4-1
[gateway]    libsoup2.4-1 libwayland-client0 libwayland-cursor0 libxcomposite1
[gateway]    libxcursor1 libxdamage1 libxfixes3 libxft2 libxi6 libxinerama1 libxkbcommon0
[gateway]    libxrandr2 python3 python3-cairo python3-chardet python3-colorama
[gateway]    python3-dbus python3-dev python3-distlib python3-gi python3-gi-cairo
[gateway]    python3-html5lib python3-minimal python3-pip python3-pkg-resources
[gateway]    python3-requests python3-setuptools python3-six python3-urllib3 python3.4
[gateway]    python3.4-dev python3.4-minimal vim vim-common vim-runtime xkb-data
[gateway]  0 upgraded, 84 newly installed, 0 to remove and 11 not upgraded.
[gateway]  Need to get 72.9 MB of archives.
...
[gateway]  Get:82 http://deb.debian.org/debian/ jessie/main python3-pip all 1.5.6-5 [97.2 kB]
[gateway]  Get:83 http://deb.debian.org/debian/ jessie/main vim-runtime all 2:7.4.488-7+deb8u3 [5048 kB]
[gateway]  Get:84 http://deb.debian.org/debian/ jessie/main vim armhf 2:7.4.488-7+deb8u3 [827 kB]
[gateway]  debconf: delaying package configuration, since apt-utils is not installed
...
[gateway]  Unpacking librest-0.7-0:armhf (0.7.92-3) ...
...
[gateway]  Preparing to unpack .../vim_2%3a7.4.488-7+deb8u3_armhf.deb ...
[gateway]  Unpacking vim (2:7.4.488-7+deb8u3) ...
[gateway]  Processing triggers for libglib2.0-0:armhf (2.42.1-1+b1) ...
[gateway]  Processing triggers for libc-bin (2.19-18+deb8u10) ...
[gateway]  Processing triggers for mime-support (3.58) ...
[gateway]  Processing triggers for hicolor-icon-theme (0.13-1) ...
[gateway]  Processing triggers for systemd (215-17+deb8u7) ...
...
[gateway]  Setting up libpython3.4-minimal:armhf (3.4.2-1) ...
...
[gateway]  Setting up python3.4 (3.4.2-1) ...
...
[gateway]  Processing triggers for systemd (215-17+deb8u7) ...
[gateway]  Processing triggers for dbus (1.8.22-0+deb8u1) ...
[gateway]  + apt-get -y autoremove
[gateway]  
[gateway]  Reading package lists...
[gateway]  Building dependency tree...
[gateway]  Reading state information...
[gateway]  0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
[gateway]  + apt-get -y autoclean
[gateway]  
[gateway]  Reading package lists...
[gateway]  Building dependency tree...
[gateway]  Reading state information...
[gateway]  + apt-get -y clean
[gateway]  
[gateway]  + rm -rf /var/lib/apt/lists/archive.raspberrypi.org_debian_dists_jessie_InRelease /var/lib/apt/lists/archive.raspberrypi.org_debian_dists_jessie_main_binary-armhf_Packages.gz /var/lib/apt/lists/archive.raspbian.org_raspbian_dists_jessie_InRelease /var/lib/apt/lists/archive.raspbian.org_raspbian_dists_jessie_contrib_binary-armhf_Packages.gz /var/lib/apt/lists/archive.raspbian.org_raspbian_dists_jessie_firmware_binary-armhf_Packages.gz /var/lib/apt/lists/archive.raspbian.org_raspbian_dists_jessie_main_binary-armhf_Packages.gz /var/lib/apt/lists/archive.raspbian.org_raspbian_dists_jessie_non-free_binary-armhf_Packages.gz /var/lib/apt/lists/archive.raspbian.org_raspbian_dists_jessie_rpi_binary-armhf_Packages.gz /var/lib/apt/lists/deb.debian.org_debian_dists_jessie-updates_InRelease /var/lib/apt/lists/deb.debian.org_debian_dists_jessie-updates_main_binary-armhf_Packages.gz /var/lib/apt/lists/deb.debian.org_debian_dists_jessie_Release /var/lib/apt/lists/deb.debian.org_debian_dists_jessie_Release.gpg /var/lib/apt/lists/deb.debian.org_debian_dists_jessie_main_binary-armhf_Packages.gz /var/lib/apt/lists/lock /var/lib/apt/lists/partial /var/lib/apt/lists/security.debian.org_dists_jessie_updates_InRelease /var/lib/apt/lists/security.debian.org_dists_jessie_updates_main_binary-armhf_Packages.gz
[gateway]  
[gateway]  + PIP_CONFIG_FILE=/root/.config/pip/pip.conf
[gateway]  + pip3 install --upgrade --ignore-installed pip setuptools
[gateway]  
[gateway]  Traceback (most recent call last):
[gateway]    File "/usr/local/bin/pip3", line 7, in <module>
[gateway]      from pip import main
[gateway]    File "/usr/lib/python3/dist-packages/pip/__init__.py", line 72, in <module>
[gateway]      from pip.log import logger
[gateway]    File "/usr/lib/python3/dist-packages/pip/log.py", line 9, in <module>
[gateway]      import colorama, pkg_resources
[gateway]    File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1520, in <module>
[gateway]      register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
[gateway]  AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
[gateway]  
[gateway]  + cp bluetooth.init /etc/init.d/bluetooth
[gateway]  
[gateway]  + cp defaults.bluetooth /etc/default/bluetooth
[gateway]  
[gateway]  + pip3 install -r ./requirements-dev.txt
[gateway]  
[gateway]  Traceback (most recent call last):
[gateway]    File "/usr/local/bin/pip3", line 7, in <module>
[gateway]      from pip import main
[gateway]    File "/usr/lib/python3/dist-packages/pip/__init__.py", line 72, in <module>
[gateway]      from pip.log import logger
[gateway]    File "/usr/lib/python3/dist-packages/pip/log.py", line 9, in <module>
[gateway]      import colorama, pkg_resources
[gateway]    File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1520, in <module>
[gateway]      register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
[gateway]  AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
[gateway]  
[gateway]  Removing intermediate container ced33db1e31d
[gateway]  The command '/bin/sh -c ./buildscripts/build.sh' returned a non-zero code: 1
[Info]     Uploading images
[Success]  Successfully uploaded images
[Error]    Some services failed to build:
[Error]      Service: gateway
[Error]        Error: The command '/bin/sh -c ./buildscripts/build.sh' returned a non-zero code: 1
[Error]    Not deploying release.

remote: error: hook declined to update refs/heads/master
To git.resin.io:g_bryn_mathias/bluetoothrelay.git
 ! [remote rejected] change-resin-image -> master (hook declined)
error: failed to push some refs to 'g_bryn_mathias@git.resin.io:g_bryn_mathias/bluetoothrelay.git'

In Resin Python base images, we’ve installed Python, pip, setuptools, virtualenv and python-bus from source so you don’t have to install them again. So can you remove python3-dbus python3-dev python3-pip from your apt-get install and try again.

That nearly worked - the problem is a missing dependency and my image has doubled in size from 300MB to >600MB.

Why is it so large?

Is there anything I can remove?

OK - unfortunately the resin imahe has python3.6 but is based on jessie.

This causes problems when installing python packages with C dependencies.

Installing python bluezero package eventually (after installing C deps one-by one as failure occurs) leads to the error below. The version of gobject-introspection is 1.46 but only 1.42 is available.
For this to work I need a python 3.6 image based on stretch which has 1.50.

This is because this image is based on jessie. jessie is too far behind to keep up with such C deps as this.

Running setup.py install for pygobject: started
[gateway]      Running setup.py install for pygobject: finished with status 'error'
[gateway]      Complete output from command /usr/local/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-zuujpegq/pygobject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-kh83jvf7-record/install-record.txt --single-version-externally-managed --compile:
[gateway]      running install
[gateway]      running build
[gateway]      running build_py
[gateway]      creating build
[gateway]      creating build/lib.linux-armv8l-3.6
[gateway]      creating build/lib.linux-armv8l-3.6/pygtkcompat
[gateway]      copying pygtkcompat/__init__.py -> build/lib.linux-armv8l-3.6/pygtkcompat
[gateway]      copying pygtkcompat/pygtkcompat.py -> build/lib.linux-armv8l-3.6/pygtkcompat
[gateway]      copying pygtkcompat/generictreemodel.py -> build/lib.linux-armv8l-3.6/pygtkcompat
[gateway]      creating build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/__init__.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/_signalhelper.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/importer.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/pygtkcompat.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/module.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/_constants.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/_ossighelper.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/_error.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/_option.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/_propertyhelper.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/docstring.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      copying gi/types.py -> build/lib.linux-armv8l-3.6/gi
[gateway]      creating build/lib.linux-armv8l-3.6/gi/repository
[gateway]      copying gi/repository/__init__.py -> build/lib.linux-armv8l-3.6/gi/repository
[gateway]      creating build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/__init__.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/GIMarshallingTests.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/Gdk.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/Gtk.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/GLib.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/Pango.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/Gio.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/GObject.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      copying gi/overrides/keysyms.py -> build/lib.linux-armv8l-3.6/gi/overrides
[gateway]      running build_ext
[gateway]      Requested 'gobject-introspection-1.0 >= 1.46.0' but version of gobject-introspection is 1.42.0
[gateway]      Command '('pkg-config', '--print-errors', '--exists', 'gobject-introspection-1.0 >= 1.46.0')' returned non-zero exit status 1.
[gateway]      ----------------------------------------
[gateway]  Command "/usr/local/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-zuujpegq/pygobject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-kh83jvf7-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-zuujpegq/pygobject/

Can I use this Dockerfile:

and change jessie to stretch?

We dont’ have a prebuilt stretch image for Python but you can use the dockerfile above, just change the tag from jessie to stretch, it will work.