Hi PYNQ community,
I’m working on building a custom Yocto (Scarthgap) image for an Ultra96-ZynqMP board using PYNQ v3.1.2 and could use some help figuring out a persistent NameError.
Goal & Setup:
-
Build a Yocto image featuring PYNQ v3.1.2.
-
Initially used
meta-xilinxrel-v2025.1(XRT 2.19.0), but encountered issues. -
Now targeting
meta-xilinxcorresponding to XRT 2024.1 (specifically202410.2.17.319). -
Using custom recipes for
python3-pynq(pointing toSRCREV = "3c77124..."- the official v3.1.2 tag),python3-pynqutils, andpython3-pynqmetadata. -
Target Python version in Yocto is 3.12.
The Problem:
When running simple PYNQ scripts on the target (like initializing an Overlay), I consistently get the following error:
[...]
File "/usr/lib/python3.12/site-packages/pynq/pl_server/xrt_device.py", line 251, in _get_handle
self.handle = pyxrt.device(self._index)
NameError: name 'pyxrt' is not defined
root:[~/notebooks]: python3 pynq_test.py
/usr/lib/python3.12/site-packages/pydantic/_internal/_config.py:334: UserWarning: Valid config keys have changed in V2:
- ‘underscore_attrs_are_private’ has been removed
warnings.warn(message, UserWarning)
/usr/lib/python3.12/site-packages/pydantic/_internal/_config.py:334: UserWarning: Valid config keys have changed in V2:- ‘underscore_attrs_are_private’ has been removed
warnings.warn(message, UserWarning)
====[ PYNQ Test Script ]====
Traceback (most recent call last):
File “/home/root/notebooks/pynq_test.py”, line 94, in
test_pynq()
File “/home/root/notebooks/pynq_test.py”, line 49, in test_pynq
overlay = Overlay(“/run/media/BOOTFS-mmcblk0p1/ultra96.itb”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/site-packages/pynq/overlay.py”, line 318, in init
super().init(bitfile_name, dtbo, partial=False, device=device)
File “/usr/lib/python3.12/site-packages/pynq/bitstream.py”, line 88, in init
device = Device.active_device
^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/site-packages/pynq/pl_server/device.py”, line 70, in active_device
if len(cls.devices) == 0:
^^^^^^^^^^^
File “/usr/lib/python3.12/site-packages/pynq/pl_server/device.py”, line 54, in devices
cls._devices.extend(DeviceMeta._subclasses[key].probe())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/site-packages/pynq/pl_server/embedded_device.py”, line 546, in probe
return [EmbeddedDevice()]
^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/site-packages/pynq/pl_server/embedded_device.py”, line 569, in init
super().init(index, tag.format(index))
File “/usr/lib/python3.12/site-packages/pynq/pl_server/xrt_device.py”, line 241, in init
self._get_handle()
File “/usr/lib/python3.12/site-packages/pynq/pl_server/xrt_device.py”, line 251, in _get_handle
self.handle = pyxrt.device(self._index)
^^^^^
NameError: name ‘pyxrt’ is not defined
root:[~/notebooks]:
This clearly indicates that the PYNQ v3.1.2 code is trying to use the pyxrt module.
Investigation & Current Yocto Approach:
-
API Mismatch Found: We initially discovered that XRT 2025.1 removed the
pyxrtAPI, hence the error. -
Official Image Analysis: We examined the official PYNQ v3.1 image for ZCU104. It uses PYNQ v3.1 with XRT v2.17.0 (2024.1) and includes a
pyxrt.sofile located at/usr/lib/python3.10/pyxrt.so. It also contains helper Python files (xrt_binding.py, etc.) in/usr/python/. TheOverlayimport works on that image. -
PYNQ Build Script (
qemu.sh) Discovery: We found a script (sdbuild/packages/xrtlib/qemu.sh) in the PYNQ v3.1.2 source repo. This script manually checks out XRT tag202410.2.17.319, patches itssrc/CMake/embedded_system.cmaketo force the Python bindings build (add_subdirectory(python)), compiles XRT, and then manually copies the resulting (misnamed).sofile to/usr/lib/pythonX.Y/pyxrt.so. -
Yocto
xrt_%.bbappendImplementation: Based on the script and official image, we created anxrt_%.bbappendfile in our Yocto layer to mimic this process:-
Forces
PREFERRED_VERSION_xrt = "202410.%". -
Adds
python3-nativeandpython3-pybind11-nativetoDEPENDS. -
Adds
EXTRA_OECMAKE = " -DXRT_BUILD_PYTHON_BINDINGS=ON". -
Applies the patch to
embedded_system.cmakeviaSRC_URI. -
Defines a new package
python3-xrtviaPACKAGES:append. -
Uses
do_install:appendto:-
Find the compiled
.so(e.g.,pyxrt.cpython-312-x86_64-linux-gnu.so) in the CMake install dir (${D}${prefix}/python). -
Move and rename it to the correct location (
${D}${libdir}/python3.12/pyxrt.so). -
Keep the other
.pyfiles (xrt_binding.py, etc.) installed by CMake in/usr/python/.
-
-
Defines
FILES:python3-xrtto include/usr/lib/python3.12/pyxrt.soand/usr/python/*.py(and parent dirs). -
Adds
LICENSEandINSANE_SKIP:already-stripped. -
Adds
RDEPENDS:${PN}:append:zynqmp = "... python3-xrt"to thepython3-pynqrecipe.
-
Current Status:
-
The Yocto image build completes successfully without packaging errors.
-
On the target,
find / -name "*pyxrt.so"correctly shows/usr/lib/python3.12/site-packages/pyxrt.so(Correction: Should be/usr/lib/python3.12/pyxrt.sobased onqemu.sh). -
The helper files like
/usr/python/xrt_binding.pyare also present. -
xbutil examine(orxrt-smi examine) works correctly, showing XRT 2.17.0. -
However, running the Python test script still results in the
NameError: name 'pyxrt' is not defined.
Question:
Despite having pyxrt.so seemingly in the correct location (/usr/lib/python3.12/, matching the official image’s pattern, though not site-packages as previously attempted) and the necessary helper .py files present, why would the import pyxrt (or subsequent use) still fail with a NameError?
-
Is there an environment variable (
PYTHONPATH?) needed, even if the.sois in/usr/lib/python3.12/? (Triedexport PYTHONPATH=/usr/python:$PYTHONPATHpreviously, didn’t help). -
Is there an initialization step missing?
-
Could the interaction between
/usr/lib/python3.12/pyxrt.soand the files in/usr/python/be broken in the Yocto build compared to theqemu.shmanual build?
Any insights into how PYNQ v3.1(.2) loads and uses pyxrt when built with XRT 2024.1 would be greatly appreciated!
NB: Some more (usefull?) information about the target system:
root:[~/notebooks]: uname -a
Linux ultra96-zynqmp 6.6.10-xilinx-gf07db70c33a8 #1 SMP Sat Apr 27 05:22:24 UTC 2024 aarch64 GNU/Linuxroot:[~/notebooks]:
root:[~/notebooks]: python3 --version
Python 3.12.11root:[~/notebooks]: xbutil examine
[ 2558.725317] zocl-drm axi:zyxclmm_drm: zocl_destroy_client: client exits pid(1042)
[ 2558.734195] zocl-drm axi:zyxclmm_drm: zocl_create_client: created KDS client for pid(1042), ret: 0
[ 2558.743193] zocl-drm axi:zyxclmm_drm: zocl_destroy_client: client exits pid(1042)
System Configuration
OS Name : Linux
Release [ 2558.753363] zocl-drm axi:zyxclmm_drm: zocl_destroy_client: client exits pid(1042)
: 6.6.10-xilinx-gf07db70c33a8
Version : #1 SMP Sat Apr 27 05:22:24 UTC 2024
Machine : aarch64
CPU Cores : 4
Memory : 1922 MB
Distribution : Demo Distribution 5.0.10
GLIBC : 2.39
Model : demo - Ultra96v2 Board [28/10/25] By Ns.
BIOS vendor : unknown
BIOS version : unknownXRT
Version : 2.17.0
Branch : 2024.1
Hash : 2c7ff250504589bd1f934010e37bdcef86afaa54
Hash Date : 2024-06-11 19:58:21
ZOCL : 2.17.0, 2c7ff250504589bd1f934010e37bdcef86afaa54
Firmware Version : N/ADevices present
BDF : Shell Logic UUID Device ID Device Ready*
[0000:00:00.0] : edge 0x0 user(inst=0) Yes
- Devices that are not ready will have reduced functionality when using XRT tools
root:[~/notebooks]:
root:[~/notebooks]: find / -name “xrt”
/etc/profile.d/xrt.sh
/home/root/notebooks/pynq_test_xrt.ipynb
/sys/devices/platform/axi/axi:zyxclmm_drm/kds_xrt_version
/usr/lib/libxrt_core.so
/usr/lib/libxrt_core.so.2
/usr/lib/libxrt_core.so.2.17.0
/usr/lib/libxrt_coreutil.so
/usr/lib/libxrt_coreutil.so.2
/usr/lib/libxrt_coreutil.so.2.17.0
/usr/lib/libxrt_hwemu.so
/usr/lib/libxrt_hwemu.so.2
/usr/lib/libxrt_hwemu.so.2.17.0
/usr/lib/libxrt++.so
/usr/lib/libxrt++.so.2
/usr/lib/libxrt++.so.2.17.0
/usr/lib/libxrt_swemu.so
/usr/lib/libxrt_swemu.so.2
/usr/lib/libxrt_swemu.so.2.17.0
/usr/lib/python3.12/site-packages/pynq/metadata/pycache/xrt_metadata_extension.cpython-312.pyc
/usr/lib/python3.12/site-packages/pynq/metadata/xrt_metadata_extension.py
/usr/lib/python3.12/site-packages/pynq/pl_server/pycache/xrt_device.cpython-312.pyc
/usr/lib/python3.12/site-packages/pynq/pl_server/xrt_device.py
/usr/lib/python3.12/site-packages/pynqmetadata/views/runtime/pycache/xrt_metadata_extension.cpython-312.pyc
/usr/lib/python3.12/site-packages/pynqmetadata/views/runtime/xrt_metadata_extension.py
/usr/lib/python3.12/site-packages/pyxrt.so
/usr/lib/xrt
/usr/python/xrt_binding.py
/usr/python/pyxrt.so
/usr/share/jupyter/kernels/python3-xrt
/usr/share/xrt_subcommands.json
root:[~/notebooks]:
Cheers,
Ns.