Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AttributeError: module 'webcolors' has no attribute 'CSS3_HEX_TO_NAMES' - fixed here #29

Description

@mykeehu

I got the following error when generating the image:

Traceback (most recent call last):
  File "I:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_MagicQuill\utils.py", line 47, in rgb_to_name
    return webcolors.rgb_to_name(rgb_tuple)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\python_embeded\Lib\site-packages\webcolors\_conversion.py", line 239, in rgb_to_name
    return hex_to_name(rgb_to_hex(normalize_integer_triplet(rgb_triplet)), spec=spec)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\python_embeded\Lib\site-packages\webcolors\_conversion.py", line 154, in hex_to_name
    raise ValueError(f'"{hex_value}" has no defined color name in {spec}.')
ValueError: "#e81111" has no defined color name in css3.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "I:\ComfyUI_windows_portable\ComfyUI\execution.py", line 327, in execute
    output_data, output_ui, has_subgraph = get_output_data(obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\execution.py", line 202, in get_output_data
    return_values = _map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\execution.py", line 174, in _map_node_over_list
    process_inputs(input_dict, i)
  File "I:\ComfyUI_windows_portable\ComfyUI\execution.py", line 163, in process_inputs
    results.append(getattr(obj, func)(**inputs))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_MagicQuill\magic_quill.py", line 204, in painter_execute
    positive_prompt = cls.guess_prompt(original_image, add_color_image, add_edge_mask)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_MagicQuill\magic_quill.py", line 184, in guess_prompt
    description, ans1, ans2 = cls.llavaModel.process(original_image_tensor, add_color_image_tensor, add_edge_mask)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_MagicQuill\llava_new.py", line 107, in process
    color = find_different_colors(image.squeeze() * 255, colored_image.squeeze() * 255)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_MagicQuill\utils.py", line 66, in find_different_colors
    color_names = [rgb_to_name(tuple(color)) for color in diff_colors]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_MagicQuill\utils.py", line 49, in rgb_to_name
    closest_name = closest_colour(rgb_tuple)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_MagicQuill\utils.py", line 37, in closest_colour
    for key, name in webcolors.CSS3_HEX_TO_NAMES.items():
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'webcolors' has no attribute 'CSS3_HEX_TO_NAMES'

It turns out that webcolors has to be called differently, here is the corrected code, which should be replaced in utils.py, from line 37 onwards with the code below:

    for name in webcolors.names("css3"):
        r_c, g_c, b_c = webcolors.name_to_rgb(name)
        rd = (r_c - requested_colour[0]) ** 2
        gd = (g_c - requested_colour[1]) ** 2
        bd = (b_c - requested_colour[2]) ** 2
        min_colours[(rd + gd + bd)] = name
    return min_colours[min(min_colours.keys())]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions