How to let base's python3 interpreter contain venv module?

I am attempting pack a cli tool write by python3, but it heavily relies on the venv module.

I tried add python3-venv as stage-packages but dont work.

Is there any other way besides build my own python3 interpreter inside snap?


As you probably already know, usually venv is only used when developing and using python packages and versions, to keep them aside from the system packages. As snaps are already isolated, there’s no real need for it inside the snap.

Is it possible to untwine venv from the process?

Are you able to share the name/repo of the tool?

pipx, a python tool install and run python applications in Isolated Environments. heavily relies on the venv module.


name: pipx 
base: core22
adopt-info: pipx
summary: execute binaries from Python packages in isolated environments 
description: |

  - build-on: amd64
  - build-on: arm64

grade: stable
confinement: strict

    command: bin/pipx
      - home
      - network
      - removable-media
      PATH: $PATH:$SNAP_USER_DATA/.local/bin

    plugin: python
    source-type: git
    source-tag: '1.5.0'
    source-depth: 1
    override-pull: |
      craftctl default
      craftctl set version=$(git describe --tags --abbrev=0)
      - python3-venv
      - -bin/Activate.ps1
      - -bin/activate
      - -bin/activate.csh
      - -bin/

Now it gives me those error message:

$ pipx install cowsay
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: /home/ubuntu/snap/pipx/x2/shared/bin/python3

'/snap/pipx/x2/bin/python3 -m venv --clear /home/ubuntu/snap/pipx/x2/shared' failed

Ah, how fun!

I suspect you need to bodge the PYTHONPATH to go along with PIPX_HOME?

Thanks, i tried , didn’t work.

I found no way to add a venv moudle to core22 python interpreter unless compile my own python3 runtime inside snap manually which increase package size significantly.

So maybe this tool isn’t suitable for snap for now …