Core snaps with python plugin using incompatible pip version 21.0

A recent version of pip (21.0) was released which drops support for Python 3.5 and Python 2

Building a snap without base specified will result in building the snap using the core base which is based on Ubuntu 16.04 which ships with python3.5 and the snap build upgrades pip to a version no longer support thus breaking any pip installs and snap build

10:56:47 Fetching and installing pip...
10:56:48 Collecting pip
10:56:48   Downloading https://files.pythonhosted.org/packages/9e/24/bc928987f35dd0167f21b13a1777c21b9c5917c9894cff93f1c1a6cb8f3b/pip-21.0.tar.gz (1.5MB)
10:56:49   Saved ./parts/SNIP/python-packages/pip-21.0.tar.gz
10:56:49 Successfully downloaded pip
10:56:50 Ignoring indexes: https://pypi.python.org/simple
10:56:50 Collecting pip
10:56:50 Building wheels for collected packages: pip
10:56:50   Running setup.py bdist_wheel for pip: started
10:56:51   Running setup.py bdist_wheel for pip: finished with status 'done'
10:56:51   Stored in directory: /root/.cache/pip/wheels/d8/1b/94/77efa18b1280b4d8696adf952ec14b2047ae73d49d46e494d6
10:56:51 Successfully built pip
10:56:51 Installing collected packages: pip
10:56:51 Successfully installed pip-8.1.1
10:56:52 Traceback (most recent call last):
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
10:56:52     "__main__", fname, loader, pkg_name)
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/usr/lib/python2.7/runpy.py", line 72, in _run_code
10:56:52     exec code in run_globals
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/lib/python2.7/site-packages/pip/__main__.py", line 21, in <module>
10:56:52     from pip._internal.cli.main import main as _main
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
10:56:52     sys.stderr.write(f"ERROR: {exc}")
10:56:52                                    ^
10:56:52 SyntaxError: invalid syntax
10:56:52 Traceback (most recent call last):
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
10:56:52     "__main__", fname, loader, pkg_name)
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/usr/lib/python2.7/runpy.py", line 72, in _run_code
10:56:52     exec code in run_globals
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/lib/python2.7/site-packages/pip/__main__.py", line 21, in <module>
10:56:52     from pip._internal.cli.main import main as _main
10:56:52   File "/root/snap-source/snap-source/parts/SNIP/install/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
10:56:52     sys.stderr.write(f"ERROR: {exc}")
10:56:52                                    ^
10:56:52 SyntaxError: invalid syntax
10:56:52 Sorry, an error occurred in Snapcraft:

The solution is to pin pip to <21.

1 Like

One option to pin is to use environment markers

pip --upgrade 'pip; python_version >= "3.6"' 'pip<21; python_version < "3.6"'

Which will install the supported version of pip on any system.

1 Like

Pull request with a proposed fix created @ https://github.com/snapcore/snapcraft/pull/3428/

Also found a workaround to override pull and install a supported pip version.

name: pip-pin-debug # you probably want to 'snapcraft register <name>'
base: core # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Debug pip pinning # 79 char long summary
description: |
  Debug pip pinning

grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots

parts:
  pip-pin-debug:
    plugin: python
    python-version: python3
    python-packages:
      - lpshipit
    override-pull: |
      apt-get install -y python3-pip
      PYTHONHOME=/usr PYTHONUSERBASE=$SNAPCRAFT_PART_INSTALL $SNAPCRAFT_PART_INSTALL/usr/bin/python3 -m pip install --upgrade 'pip; python_version >= "3.6"' 'pip<21; python_version < "3.6"' --user
      snapcraftctl pull
3 Likes