Issue with PYNQ Overlay Load Failing via systemd Service on Zynq-7000 (XC7Z020)

I am currently developing a project using PYNQ v3.0.1 on a Zynq-7000 SoC (XC7Z020) board. As part of the system architecture, I start a Flask server automatically during boot using a systemd service. This service executes a Python script (app.py) which initializes the PYNQ environment and loads a custom overlay (bitstream) using the Overlay class.

However, when the script is started via the systemd service, I encounter the following error during the overlay loading step:
RuntimeError: No Device Found

In contrast, when I manually execute the same app.py script from the terminal (using the same environment and user), the overlay is successfully downloaded and the Flask server runs as expected.

To isolate the issue, I ensured that:

  • The systemd service is executed as the xilinx user.
  • The appropriate environment variables and virtual environment for PYNQ are sourced in the service.
  • The FPGA overlay file is accessible and correctly specified.
  • The script executes correctly outside of the systemd context.

Summary:

  • Board: Zynq-7000 XC7Z020
  • PYNQ Version: 3.0.1
  • Problem: Overlay fails with RuntimeError: No Devices Found when executed via systemd, but works when run manually.
  • Suspected Cause: Systemd service environment or hardware context not matching interactive shell.

Are there any suggestions for solving this problem to use PYNQ under systemd?

Thanks!

Hi @maximilianbeutel

Welcome to the PYNQ community.
The service should be run as root which is where the pynq env is installed.

If this still fails, you may want to source the env.

See related issues:

Mario

Hello Mario, thank you for your reply.

I’ve now modified the systemd service to run as root, and ensured that the pynq virtual environment is being used. However, I still encounter the following error when trying to load the overlay via Overlay():

RuntimeError: No Devices Found

The error traceback points to the line where the overlay is instantiated:

self.overlay = Overlay(self.bitfile_path, download=True)

Here are some more details:

  • If I manually run the same script using the pynq-venv Python interpreter from the terminal, everything works fine and the overlay loads successfully.
  • When the same script is started via systemd, even as root and with the environment sourced correctly, I get the “No Devices Found” error.
  • The systemd service is configured to launch the Python script using the full path to the virtual environment:
ExecStart=/usr/local/share/pynq-venv/bin/python3 /home/xilinx/sys1/start_server.py
  • PYNQ is found (no ModuleNotFoundError), so the virtual environment is activated correctly.

Based on the traceback, the failure happens when Device.active_device is accessed in the PYNQ source code. This seems to indicate that under systemd, the script fails to detect the FPGA device at runtime.

Full Error:
May 21 11:00:15 AX7020B001 bash[3513]: phydriver=Driver()
May 21 11:00:15 AX7020B001 bash[3513]: File “/home/xilinx/sys1/sys2/device/driver.py”, line 23, in init
May 21 11:00:15 AX7020B001 bash[3513]: self.overlay = Overlay(self.bitfile_path, download=True) # loads the metadata
May 21 11:00:15 AX7020B001 bash[3513]: File “/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/overlay.py”, line 315, in init
May 21 11:00:15 AX7020B001 bash[3513]: super().init(bitfile_name, dtbo, partial=False, device=device)
May 21 11:00:15 AX7020B001 bash[3513]: File “/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/bitstream.py”, line 88, in init
May 21 11:00:15 AX7020B001 bash[3513]: device = Device.active_device
May 21 11:00:15 AX7020B001 bash[3513]: File “/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/device.py”, line 71, in active_device
May 21 11:00:15 AX7020B001 bash[3513]: raise RuntimeError(“No Devices Found”)
May 21 11:00:15 AX7020B001 bash[3513]: RuntimeError: No Devices Found.

Do you have suggestions for debugging or ensuring that the hardware context is available to the Python process when invoked via systemd?

Did you try sourcing XRT as indicated in the other post?