Problems with Yocto python3 virtual environments

Hello,

I’m building a Yocto image for use with the Verdin imx8mp SoM.

I have included python3-pip, and python3-venv in my image. My problem is that I can’t create a python virtual environment.

If I try python3 -m venv /tmp/venv, it fails with a warning that there is no module named ensurepip.

If I use pip3 to install virtualenv, that also fails:

pip3 install virtualenv
virtualenv /tmp/myenv

ModuleNotFoundError: No module named 'timeit'

I suspect that this is due to the python3 recipe building a minimal python3 that doesn’t include these normall builtin modules.

What is the most straightforward path to getting python virtual environments working on my Verdin?

tdx-info output:

cat: can't open '/etc/hostname': No such file or directory

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           6.6.54-7.1.0-devel-g3493ccd66900 #1 SMP PREEMPT Tue Dec 17 21:04:41 UTC 2024
Kernel command line:      root=PARTUUID=66a95b8d-02 ro rootwait console=tty1 console=ttymxc2,115200
Distro name:              NAME="TDX Wayland with XWayland"
Distro version:           VERSION_ID=7.1.0-devel-20250116210215-build.0
Distro variant:           -
Hostname:                 -
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Customer Carrier Board with Toradex Verdin iMX8MP
Toradex version:          0058 V1.1B
Serial number:            15446066
Processor arch:           aarch64
Available block devices:
                          NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
                          mmcblk2 179:0 0 29.1G 0 disk
                          mmcblk2p1 179:1 0 48M 0 part /run/media/BOOT-mmcblk2p1
                          mmcblk2p2 179:2 0 29.1G 0 part /
                          mmcblk2boot0 179:8 0 4M 1 disk
                          mmcblk2boot1 179:16 0 4M 1 disk
                          mmcblk1 179:24 0 7.4G 0 disk
                          mmcblk1p1 179:25 0 7.4G 0 part /run/media/OASIS-mmcblk1p1
------------------------------------------------------------

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

Thank you for reaching out with your question. The issue you’re encountering with creating Python virtual environments on your Yocto-based image for the Verdin iMX8MP SoM is likely due to the minimal Python build that Yocto typically provides. This build may not include all standard library modules, such as ‘ensurepip’ and ‘timeit’, which are necessary for creating virtual environments.

To resolve this, you have a couple of options:

  1. Modify the Yocto Build: You can customize your Yocto build to include the missing Python modules. This involves modifying the Python recipe in your Yocto layers to ensure that all necessary modules are included. You may need to add additional dependencies or adjust the configuration to include a more complete Python installation.

  2. Use TorizonCore with Debian Containers: An alternative approach is to use TorizonCore, which is a ready-to-use distribution from Toradex that supports containerized applications. By using Debian-based containers, you can leverage a full Python environment with all necessary modules included. This approach simplifies dependency management and avoids the need to modify the Yocto build.

In a containerized environment, the need for virtual environments is reduced, as each container can be configured with its own dependencies and isolated from the host system. This makes it easier to manage Python applications and their dependencies.

These solutions should help you set up a working Python environment on your Verdin iMX8MP SoM. If you decide to stick with Yocto, ensure that your build configuration includes all necessary Python components. Otherwise, consider the benefits of using TorizonCore for a more streamlined development process.

Best regards, Toradex AI Assistant.

Please, also check if these links can help you solve your problem:

Linux-toradex task fails while compiling using Yocto project.

I was able to solve this by adding python3-modules to my image. Apparently this includes all the stdlib modules that aren’t included in the minimal (default) python3 installation.

In addition, I added packagegroup-core-buildessential, python3-venv and python3-dev. These allow me to build pip modules that can’t be simply downloaded (such as netifaces).

Hey @Louie,

Glad to hear you solved it. Thanks for the update.