XpressAI/xircuits

Cannot run custom components ModuleNotFoundError: No module named 'xai_components.xai_template.xxx'

Closed this issue · 4 comments

esgnn commented

What kind of bug is it?

  • [ x] Xircuits Core (Jupyterlab related features)
  • Xircuits Canvas (Custom RD related features)
  • Xircuits Component Library
  • Testing Automation
  • Documentation
  • Not Sure

Describe the bug
Followed the Creating a Xircuits Component from the documentation. I can drag the new component into the canvas and connect it with appropriate nodes. When I run I get
ModuleNotFoundError: No module named 'xai_components.xai_template.SampleComponent'

To Reproduce
Steps to reproduce the behavior:

  1. Follow How to Create a Xircuits Component instructions under Creating a Xircuits Component
  2. Drag and drop HelloNewLibrary node under Templates
  3. Connect it with start, end, and Literal String nodes
  4. Save
  5. Compile Xcircuits
  6. Run
  7. Select Kernel (virtual environment's Kernel) (tried with other Kernel's as well)

Expected behavior
print("Hello " + input_str)

Screenshots
If applicable, add screenshots to help explain your problem.

Tested on?

  • [x ] Windows
  • Linux Ubuntu
  • Centos
  • Mac
  • Others (State here -> xxx )

Additional context
Add any other context about the problem here.

Hey there! Thanks for sharing the details about the bug you've come across. It seems like the component parser is unable to find the SampleComponent and/or HelloNewLibrary component. Let's try a few simple troubleshooting steps to help you out:

  1. Double-check the SampleComponent and/or HelloNewLibrary component - Make sure these component codes are located in the xai_components/xai_templates directory from your base working directory. Also don't forget to save your changes. Keep in mind that JupyterLab doesn't automatically save your changes like vscode. So, make sure you've saved any new components or changes you've made.

  2. Give the node in the Xircuits Canvas a quick refresh: Simply right-click the node in the canvas and choose 'Reload Node.' If this fixes the issue, it means the node in the canvas was still pointing to an old reference path.

If you've tried these suggestions and still can't solve the issue, please feel free to share more information or any error messages you've come across. Also mention the Xircuits version you're running, you should be able to know it by running pip show xircuits in your venv. We're here to help you!

esgnn commented

Hey, thanks for the quick reply.
I tried 1 and 2 but no luck.
When I created the files under
C:\Users\userxxx\miniconda3\envs\myenv\lib\site-packages\xai_components\xai_myLib, it works. It wasn't working until I restarted the jupyter lab (to be honest it feels like I've already restarted it without any luck, but maybe I was confused).
So, the problem seems like there is a problem with reading from virtual environment subfolders. By the way, the compiled .py file is automatically created under venv folder.
Another interesting thing is that, when I first started jupyter lab, there were no xircuits nodes available. I had to run xircuits-examples again.
My xircuits version is 1.8.0

Ah, I might know the cause. Try this:

  1. Make a new directory anywhere, cd to it and activate your venv. Install Xircuits if you haven't.
  2. It will offer to load the xircuits components in your current dir. Do so.
  3. Xircuits will then launch. Try dragging in any nodes.

If this works then the explanation:
When you work with Xircuits, typically you would only work on one working directory at a time, let's say C:\Users\userxxx\MyXircuitsProject. When you first launch Xircuits in this dir, it will copy over the xai_components dir from the site-packages. This should be the component dir that the component parser expects, and where you should edit and modify your component codes instead of the one in the site-packages.

Since there hasn't been any updates for 2 weeks, I'm guessing that means things are all sorted out now.
I'll go ahead and close this issue, but please don't hesitate to reopen it if you need any more help! 😄