OSError: Root permissions required

Hi all !

I’m trying to run an example with a tf2 xmodel using pynq from the command line but unable to proceed because of an error about permissions.

I’m only with two lines of code - because it is just an example:

from pynq_dpu import DpuOverlay

# set DPU
overlay = DpuOverlay("dpu.bit")

I’ve started my CLI session with

source /etc/profile.d/pynq_venv.sh

so I can have the pynq environment.

When I run the example above (be in a script of from the Python console):

(pynq-venv) ubuntu@kria:~/myModel$ python
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pynq_dpu import DpuOverlay
>>> overlay = DpuOverlay("dpu.bit")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq_dpu/dpu.py", line 98, in __init__
    super().__init__(abs_bitfile_name,
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/overlay.py", line 348, in __init__
    self.download()
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq_dpu/dpu.py", line 116, in download
    super().download()
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/overlay.py", line 424, in download
    Clocks.set_pl_clk(i, div0, div1)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/ps.py", line 303, in set_pl_clk
    cls._instance.set_pl_clk(clk_idx, div0, div1, clk_mhz)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/ps.py", line 311, in _instance
    cls._real_instance = _ClocksUltrascale()
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/ps.py", line 463, in __init__
    self._crf_mmio = MMIO(self.CRF_APB_ADDRESS, 0x100)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/mmio.py", line 73, in __init__
    self.array = self.device.mmap(base_addr, length)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/embedded_device.py", line 581, in mmap
    raise EnvironmentError("Root permissions required.")
OSError: Root permissions required.
>>> 

If I try sudo python

(pynq-venv) ubuntu@kria:~/myModel$ sudo python runit.py 
Traceback (most recent call last):
  File "/home/ubuntu/myModel/runit.py", line 1, in <module>
    from pynq_dpu import DpuOverlay
ModuleNotFoundError: No module named 'pynq_dpu'

How can I run the two lines without a notebook ?
Thank you

I have the latest PYNQ version and on Ubuntu in a Xilinx Kria KV260

Hi there,

When you invoke sudo it runs the command in a new shell session as root, without carrying over the environment settings from your previous session. The way I’d recommend to do it in a command line environment is to:

sudo -i
source /etc/profile.d/pynq_venv.sh
python3 runit.py

That way you login as the root user and setup the pynq_venv with associated env variables. This should be equivalent to opening a terminal on a pynq image with jupyterlab.

Thanks
Shawn

You can also edit your sudoers file on your board so that certain environment variables are kept when you run sudo. For me it’s sufficient to keep the BOARD and XILINX_XRT variables set. The sudoers has to be edited with sudo visudo. I just added the lines

Defaults env_keep="BOARD"
Defaults env_keep+="XILINX_XRT"

So my file looks like

This might be bad practice but could be more convenient depending on how you want to run your system!

Best,
Jenny

Thank you both.
I’ll try to do that.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.