AIrjen / OneButtonPrompt

One Button Prompt
GNU General Public License v3.0
875 stars 87 forks source link

Imports not working on ComfyUI #105

Closed powerfulparadox closed 1 year ago

powerfulparadox commented 1 year ago

I'm moving to ComfyUI from Automatic1111 and was pleased to discover that OneButtonPrompt exists for ComfyUI as well. Unfortunately, when I start ComfyUI (latest commit as of posting is https://github.com/comfyanonymous/ComfyUI/commit/0cb14a33f607da8e93c4ab02047170deb6a33dae which is the commit I'm using) I get the following:

12:02:23 - ReActor Node - STATUS - Running v0.1.0 in ComfyUI
Traceback (most recent call last):
  File "/home/user/ComfyUI/nodes.py", line 1647, in load_custom_node
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/user/ComfyUI/custom_nodes/OneButtonPrompt/__init__.py", line 1, in <module>
    from .OneButtonPromptNodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
  File "/home/user/ComfyUI/custom_nodes/OneButtonPrompt/OneButtonPromptNodes.py", line 13, in <module>
    from build_dynamic_prompt import *
ModuleNotFoundError: No module named 'build_dynamic_prompt'

Cannot import /home/user/ComfyUI/custom_nodes/OneButtonPrompt module for custom nodes: No module named 'build_dynamic_prompt'

With a bit of detective work from the error, I tried changing

from build_dynamic_prompt import *

to

from .build_dynamic_prompt import *

in OneButtonPromptNodes.py

That got me this error:

12:09:35 - ReActor Node - STATUS - Running v0.1.0 in ComfyUI
Traceback (most recent call last):
  File "/home/user/ComfyUI/nodes.py", line 1647, in load_custom_node
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/user/ComfyUI/custom_nodes/OneButtonPrompt/__init__.py", line 1, in <module>
    from .OneButtonPromptNodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
  File "/home/user/ComfyUI/custom_nodes/OneButtonPrompt/OneButtonPromptNodes.py", line 13, in <module>
    from .build_dynamic_prompt import *
  File "/home/user/ComfyUI/custom_nodes/OneButtonPrompt/build_dynamic_prompt.py", line 3, in <module>
    from csv_reader import *
ModuleNotFoundError: No module named 'csv_reader'

Cannot import /home/user/ComfyUI/custom_nodes/OneButtonPrompt module for custom nodes: No module named 'csv_reader'

So I changed build_dynamic_promt.py from

from csv_reader import *
from random_functions import *

to

from .csv_reader import *
from .random_functions import *

and things seem to work properly now.

I'm using AMD Rocm and Python 3.11, in case that's relevant. I'm not familiar with Git/GitHub enough to be comfortable trying to make a pull request, and I'm not familiar enough with the projects involved here to know how useful (or not) my changes are in the grand scheme of things. I haven't tested these changes against Automatic1111 to know if they break anything there, for example. But this should document my amateur attempt to get this working for my needs, and if it turns out to fix something that's broken more widely, I hope my experience is useful.

AIrjen commented 1 year ago

Thanks for reporting and even posting a fix. Ill take an in depth look soon into this!

longMaxWoods commented 1 year ago

Thanks, this worked like a charm for me. Different line numbers but same lines of code. Python 3.11.4, cuda, fedora 38

AIrjen commented 1 year ago

I've pushed a potential fix. The potential given solution actually created the reverse problem on my computer.

I have no way to test though, so please let me know if the changes I made now work.

powerfulparadox commented 1 year ago

Sadly I'm still getting the same error, and exactly the same changes fix it for me.

I momentarily convinced myself that the problem was my virtual environment being in my Automatic1111 folder, not my ComfyUI folder, and made a ComfyUI-local copy to test. But I hadn't reverted my own change, so of course it ran fine. Putting things back to the way you changed them still caused the problem.

So now I'm officially out of ideas. I can see why your change theoretically should help, but it clearly doesn't on my end.

If I wasn't just flying by the seat of my pants with error messages and documentation I could probably be more help, but sadly I'm just an amateur good at poking things.

AIrjen commented 1 year ago

Hi! Thanks for checking out if it works. It's hard to fix something I can't reproduce. (works on my computer syndrome, coding is hard!) The main problem for me is that the .type fix will break the integration in A1111. So I have to look for other solutions.

I will try again when I have time, to see if I can make another potential fix. I guess we have to try stuff out. I will look at how other nodes have solved this.

ps, I am also just an amateur good at poking things!

AIrjen commented 1 year ago

OK! I have another try up. It may be that it is caused by me using case-sensitive and non-case sensitive names in the folders. So I made it consistent. I think it messed up on Linux because of this.

Let me know if this works?

longMaxWoods commented 1 year ago

Yes, this worked perfectly! Although I'm not sure I tested it correctly. I deleted the old folder (because it was working) did a git pull for the new folder any everything loaded smooth as silk without errors.

Sent with Proton Mail secure email.

------- Original Message ------- On Tuesday, August 8th, 2023 at 9:37 AM, AIrjen @.***> wrote:

OK! I have another try up. It may be that it is caused by me using case-sensitive and non-case sensitive names in the folders. So I made it consistent. I think it messed up on Linux because of this.

Let me know if this works?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

powerfulparadox commented 1 year ago

It also loads correctly for me. Thanks again for your excellent work and for tracking down a more robust way to fix the problem.

AIrjen commented 1 year ago

Thanks for confirming and helping to solve. You are all amazing!