Running PYNQ on Pycharm or other IDE for Python

Hello, I am trying to use pynq on Pycharm or other Pyhton IDE instead of using Jupyter Notebook. Is it posibble? How can I do it?
Thank you very much.

Yes ! It is possible and very simple.

I’ve spent some time working on this. I haven’t been able to get every feature (python console, interactive plotting, to name a few) but I am able to remotely execute code, download an overlay / access ip, use the debugger, make plots, etc.

Here’s how I do it with PYNQ3.0.1 and Pycharm Professional 2022.2.2.:

  1. Make sure you are able to log into your board via ssh.
  2. In Pycharm preferences under “Deployment” set up an ssh configuration to xilinx@<your.board.ip.or.hostname>. Enter the login credentials and check the box for “execute commands with sudo”.
    Optional: Configure a path mapping between your Pycharm project and wherever you want the code to live on your board with the “mappings” tab. You can also push/pull code to your board via Github or use scp but I find the mapping is the most convinient. I cloned the python package I am working on to a folder I made. I then installed my cloned package in the pynq-venv with the editable flag. I have a mapping from my project to the package location on my board so I can deploy the code and test it. If you do this make sure you are happy with the behavior specified in Preferences > Deployment > Options.
  3. **Go to Preferences > Console and find the remote Python 3.10.4 in the pynq-venv. It should be in /usr/local/share/pynq-venv/bin/python. Configure the “Environment variables” for BOARD and XILINX_XRT and optionally add some imports or whatever you want initialized in your Python console under “Starting script”

    You can find your board name variable by running cat /proc/device-tree/chosen/pynq_board | tr '\0' '\n' on your board. You can see the correct XILINX_XRT in /etc/profile.d/xrt_setup.sh. You should now have access to a Python console running on the board.
  4. In the upper right-hand corner, click the down arrow then “Edit Configurations” to create a new run configuration or edit and existing one:

    Again point the Python interpreter to the remote pynq-venv and set the environment variables for BOARD and XILINX_XRT. **Make sure “Run with Python Console” is not checked.
  5. You should now be able to deploy the code for that run configuration to the board and use that run configuration, set breakpoints in the code and use the debugger, etc.

** I have not been able to load an overlay using the Python Console. It’s something to do with asyncio event loops. Whenever I try to load an overlay using the console I get:

from pynq import Overlay
ol = Overlay('/home/xilinx/bit/cordic_16_15_fir_22_0.bit')
Exception ignored in: <function UioController.__del__ at 0xffff688c4d30>
Traceback (most recent call last):
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/uio.py", line 79, in __del__
    asyncio.get_event_loop().remove_reader(self.uio)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/nest_asyncio.py", line 45, in _get_event_loop
    loop = events.get_event_loop_policy().get_event_loop()
  File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-4 (handle)'.
Exception ignored in: <function UioController.__del__ at 0xffff688c4d30>
Traceback (most recent call last):
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/uio.py", line 79, in __del__
    asyncio.get_event_loop().remove_reader(self.uio)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/nest_asyncio.py", line 45, in _get_event_loop
    loop = events.get_event_loop_policy().get_event_loop()
  File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-4 (handle)'.
Exception ignored in: <function UioController.__del__ at 0xffff688c4d30>
Traceback (most recent call last):
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/uio.py", line 79, in __del__
    asyncio.get_event_loop().remove_reader(self.uio)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/nest_asyncio.py", line 45, in _get_event_loop
    loop = events.get_event_loop_policy().get_event_loop()
  File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-4 (handle)'.
Exception ignored in: <function UioController.__del__ at 0xffff688c4d30>
Traceback (most recent call last):
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/uio.py", line 79, in __del__
    asyncio.get_event_loop().remove_reader(self.uio)
  File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/nest_asyncio.py", line 45, in _get_event_loop
    loop = events.get_event_loop_policy().get_event_loop()
  File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-4 (handle)'.

I have tried starting an event loop before trying to load the overlay:

import asyncio
aloop = asyncio.new_event_loop()
asyncio.set_event_loop(aloop)

But the loop isn’t running. I have tried a variety of asyncio calls to get an event loop with no success. If someone has figured that part out I would greatly appreciate some tips! But for now it’s fine for me to just use run configurations without the console.

One last note: the only way I have been able to view plots executed on the board in Pycharm is using the SciView. I would prefer a pop up with an interactive plot but I haven’t been able to figure that out.

Hope this helps and anyone please feel free to contribute more insight!

4 Likes