Thanks for the ppa
tip which worked installing python 3.9 on core18.
I also finally got Python 3.8 working on core18
, when I figured out that the command to invoke is command: python3.8 src/main.py
which resolves to usr/bin/python3.8
, and not to use command: python3 src/main.py
which resolves to usr/bin/python3
which is the old Python 3.6.
Note: It turns out that using the python3.*-venv
approach under core18
and core20
results in different locations for the resulting Python executables and thus in the command:
invocations you need to use. I’ve gone into detail below, but from these results, it seems that the command invocation you can safely use in all cases (core18, core20), is usr/bin/python3.9
.
Click to expand - details on the different locations of the resulting Python executables
Assuming your snapcraft file contains as per @om26er above, here are the locations of the installed Pythons:
Note all these paths are relative to ‘prime’ which ends up as the root of the deployed snap (see my article).
- Under
core18
the Python you want is in usr/bin/python3.9
not usr/bin/python3
(which is the old Python 3.6). Also, bin/python*
files do not exist (like they do in core20). So you should e.g.
command: usr/bin/python3.9 -V
command: python3.9 -V
command: python3 -V
No!
- Under
core20
the Python you want is in bin/python3
or bin/python
or bin/python3.9
. You can also reference usr/bin/python3.9
. The old default Python doesn’t seem to be anywhere I can find in the resulting snap, which is good - less confusion. So you should e.g.
command: usr/bin/python3.9 -V
command: bin/python3.9 -V
command: bin/python3 -V
command: python3.9 -V
No! Snapcraft can’t auto-resolve this Python to anything
The example command:
invocations above pass the parameter -V
just to print the Python version number, normally you would pass the path to your Python script.
From these results, it seems that the command invocation you can safely use in all cases (core18, core20), is usr/bin/python3.9
for example
command: usr/bin/python3.9 src/main.py
P.S. Not sure how this Python location information relates to the SNAPCRAFT_PYTHON_INTERPRETER
setting, nor how it relates to the (now defunct as of core20) Python plugin python-version:
setting.
What about pip installed packages?
The python3.*-venv
approach, whilst successfully installing a Python of our choice, unfortunately under core20 it doesn’t seem to make my Python packages available, given I have the usual
requirements:
- /root/project/requirements.txt
section in my snapcraft.yaml
file. Interestingly, with the same snapcraft file (adjusted for core18/core20) Python does have access to packages in the resulting snap under core18
, just not under core20
.