Issue using python3 venv module

Creating a bug report/issue

I have searched the existing open and closed issues

Required Information

  • DietPi version:
    G_DIETPI_VERSION_CORE=9
    G_DIETPI_VERSION_SUB=8
  • Distro version
    bookworm 0

Additional Information (if applicable)

python3

Steps to reproduce

Context: I want to automate my rpi5 installation using dietpi first boot text file and post installation script.

So I used the automatic dietpi installation and installed the software:
130 Python 3: Runtime system, pip package installer and development headers

And then I try to run the script:

#!/bin/bash
####################################
#
# Script to execute after dietpi
# initial installation.
#
####################################
dir_location=/opt/shared

mkdir $dir_location; cd $dir_location && python3 -m venv env && env/bin/python3 -m pip install requests

Expected behaviour

I expect the virtual environment env to be created and usable.

Actual behaviour

I have the error:

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.11-venv

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

Failing command: /opt/shared/env/bin/python3

Extra details

How I could avoid this issue / fully automate my venv creation?

Sincerely

Does it work from CLI? If yes, maybe try to call python with an absolute path from inside the script.

...
mkdir $dir_location; cd $dir_location && /usr/bin/python3 -m venv env && env/bin/python3 -m pip install requests

By default, we only install the Python packages and do not create a virtual environment right at the start. For some applications such as HA, we create our own virtual environment via pyenv during the installation.

If you need the packet python3.11-venv right from the start, you would have to install it via the ‘post-DietPi’ install script.

I did it and indeed it worked, thanks for the support :slight_smile: