Python plugin sys.path uses full path in base 20

using base: core18 the sys.path uses : $SNAP/ for example:

 >>> import sys
 >>> print('\n'.join(sys.path))
 
 /snap/ubu18/x1/usr/lib/python36.zip
 /snap/ubu18/x1/usr/lib/python3.6
 /snap/ubu18/x1/usr/lib/python3.6/lib-dynload
 /snap/ubu18/x1/usr/lib/python3/dist-packages
 /snap/ubu18/x1/lib/python3.6/site-packages

using base: core20 the sys.path uses full path:

 >>> import sys
 >>> print('\n'.join(sys.path))
 
 /usr/lib/python38.zip
 /usr/lib/python3.8
 /usr/lib/python3.8/lib-dynload
 /usr/lib/python3/dist-packages
 /lib/python3.8/site-packages

is it a bug?
is there a good aproach to “fix” the path in core base 20?

I only found one way to do that.
I needed to create a shell script that set environment variables:

start.sh:

PYTHONPATH="$SNAP/usr/lib/python38.zip:$SNAP/usr/lib/python3.8:$SNAP/usr/lib/python3.8/lib-dynload:$SNAP/usr/lib/python3/dist-packages:$SNAP/lib/python3.8/site-packages" python3 $SNAP/bin/ubu20.py

snapcraft.yaml:

    command: start.sh

override-stage didn’t work, setting environment variables here, doesn’t affect when running the app.

Rather than setting the env variable as part of the command itself, you should be able to achieve the same runtime setting with:

environment:
  PYTHONPATH: <path>

or

apps:
  <app name>:
    environment:
      PYTHONPATH: <path>

Regarding the path discrepancy between 18 and 20, I have no idea if it’s a bug. Can you post more of your snapcraft.yaml for us to see?

hi @goodsoftworx thanks. I built two very simple projects only to test.

snapcraft.yaml for core18:

name: ubu18
base: core18
version: '1'
summary: 79 char long summary
description: |
  This is my-snap's description.

grade: devel
confinement: devmode

apps:

  ubu18:
    command: bin/ubu18.py
    plugs:
    - home
    - x11
    - desktop
    - wayland

parts:

  ubu18:
    plugin: python
    source: .
    stage-packages:
      - python3-tk
      - tk-dev
      - python-tk
    requirements: ['./requirements.txt']

  dump-files:
    plugin: dump
    source: .
    organize:
      ubu18.py: bin/

snapcraft.yaml for core20

name: ubu20
base: core20
version: '1'
summary: 79 char long summary
description: |
  This is my-snap's description.

grade: devel
confinement: devmode

apps:

  ubu20:
    command: bin/ubu20.py
    plugs:
    - pulseaudio
    - home
    - audio-playback
    - x11
    - desktop
    - wayland

parts:

  ubu20:
    plugin: python
    source: .
    stage-packages:
      - python3.8-tk
      - tk-dev
      - python-tk
    python-packages:
      - tk-tools
      - customtkinter

  dump-files:
    plugin: dump
    source: .
    organize:
      ubu20.py: bin/