Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Failed - No Matter What I Do? #2

Open
Evilander opened this issue Jan 10, 2024 · 14 comments
Open

Import Failed - No Matter What I Do? #2

Evilander opened this issue Jan 10, 2024 · 14 comments

Comments

@Evilander
Copy link

Evilander commented Jan 10, 2024

C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery../../web/extensions/core/uploadImage.js
Original code block not found.❌
File 'C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery../../folder_paths.py' updated successfully.✅
Traceback (most recent call last):
File "C:\ComfyUI_windows_portable\ComfyUI\nodes.py", line 1800, in load_custom_node
module_spec.loader.exec_module(module)
File "", line 940, in exec_module
File "", line 241, in call_with_frames_removed
File "C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery_init
.py", line 256, in
modify_wedgets_js_file(wedgets_js_file_path, new_wedgets_js_content, new_wedgets_js_content_2)
File "C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery_init_.py", line 153, in modify_wedgets_js_file
file.write(content)
File "encodings\cp1252.py", line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode characters in position 6973-6981: character maps to

Cannot import C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-ArtGallery module for custom nodes: 'charmap' codec can't encode characters in position 6973-6981: character maps to
I have tried everything - I believe?

@Poukpalaova
Copy link

Same problem here. non ascii char at 6973-6981, maybe some chinese char in the file. I found some but didn't helped me to rename it.

@LeroyDaydreamer
Copy link

LeroyDaydreamer commented Jan 28, 2024

I had ChatGPT helping me to fix the code and translate the comments. Bascially utf-8 support must be added to the file operations. Error handling was added too because some ComfyUI core files are modified and if this fails, they'll be wiped. So before you start, update ComfyUI so it can restore the files that got broken so far. Then the following 3 methods in the init.py of the node must be changed:
modify_js_file
modify_wedgets_js_file
modify_py_file

You can just replace them with the code below accordingly:

modify_js_file

def modify_js_file(file_path, new_content):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()

        # Check if new content is already included
        if "image_upload_artist" not in content:
            insert_position = content.find('nodeData.input.required.upload = ["IMAGEUPLOAD"];')
            if insert_position != -1:
                insert_position += len('nodeData.input.required.upload = ["IMAGEUPLOAD"];')
                content = content[:insert_position] + new_content + content[insert_position:]

                # Backup the original file
                backup_path = file_path + '.backup'
                with open(backup_path, 'w', encoding='utf-8') as backup_file:
                    backup_file.write(content)

                # Write modified content back to file
                with open(file_path, 'w', encoding='utf-8') as file:
                    file.write(content)
                print(f"File '{file_path}' updated successfully.✅")
            else:
                print("Original code block not found.❌")
        else:
            print("File already contains the necessary modifications.✅")
    except Exception as e:
        print(f"An error occurred: {e}")

modify_wedgets_js_file

def modify_wedgets_js_file(file_path, new_content, new_content_2):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()

        # Check if the file already contains the content to be added
        if "ARTISTS_IMAGEUPLOAD" not in content:
            # Find the position of the original code
            insert_position = content.find('return (display==="slider") ? "slider" : "number"')
            if insert_position != -1:
                # Insert new code after the original code
                insert_position += len('return (display==="slider") ? "slider" : "number"')
                content = content[:insert_position] + new_content + content[insert_position:]

            insert_position_2 = content.find('return { widget: uploadWidget };')
            if insert_position_2 != -1:
                # Insert new code after the original code
                insert_position_2 += len('return { widget: uploadWidget };')
                content = content[:insert_position_2] + new_content_2 + content[insert_position_2:]

                # Backup the original file
                backup_path = file_path + '.backup'
                with open(backup_path, 'w', encoding='utf-8') as backup_file:
                    backup_file.write(content)

                # Write back the file
                with open(file_path, 'w', encoding='utf-8') as file:
                    file.write(content)
                print(f"File '{file_path}' updated successfully.✅")
            else:
                print("Original code block not found.❌")
        else:
            print("File already contains the necessary modifications.✅")
    except Exception as e:
        print(f"An error occurred: {e}")

modify_py_file

def modify_py_file(file_path, new_content, search_line, function_content, search_function):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            lines = file.readlines()

        # Prepare key lines of new content and function content for comparison
        new_content_key_line = new_content.strip().split('\n')[0]
        function_content_key_line = function_content.strip().split('\n')[0]

        # Check if new content already exists
        if new_content_key_line not in "".join(lines):
            for index, line in enumerate(lines):
                if search_line in line:
                    lines.insert(index + 1, new_content)
                    break

        # Check if function modification already exists
        if function_content_key_line not in "".join(lines):
            function_start = False
            for index, line in enumerate(lines):
                if search_function in line:
                    function_start = True
                if function_start and "return None" in line:
                    lines.insert(index, function_content)
                    break

        # Backup the original file
        backup_path = file_path + '.backup'
        with open(backup_path, 'w', encoding='utf-8') as backup_file:
            backup_file.writelines(lines)

        # Write back the modified content
        with open(file_path, 'w', encoding='utf-8') as file:
            file.writelines(lines)
        print(f"File '{file_path}' updated successfully.✅")

    except Exception as e:
        print(f"An error occurred: {e}")

@Muabf
Copy link

Muabf commented Feb 3, 2024

your fix worked thank you. but a final one that I could use your help on is the TranslateTextNode. that one is also missing.

image

@LeroyDaydreamer
Copy link

This doesn't seem to be related to this repository. There's a package in ComfyUIs manager showing up though that contains a node named TranslateText. If you got it from that pack, update/fix it using the manager. If it doesn't work uninstall the package that contains it also using the manager and then reinstall it.

@water110
Copy link

water110 commented Aug 4, 2024

上面的方法成功帮我修复了文件名包含中文时GBK编码问题!

@jgiddens
Copy link

Thanks @LeroyDaydreamer !! Your code changes fixed it for me!

@shanguanding
Copy link

I had ChatGPT helping me to fix the code and translate the comments. Bascially utf-8 support must be added to the file operations. Error handling was added too because some ComfyUI core files are modified and if this fails, they'll be wiped. So before you start, update ComfyUI so it can restore the files that got broken so far. Then the following 3 methods in the init.py of the node must be changed: modify_js_file modify_wedgets_js_file modify_py_file

You can just replace them with the code below accordingly:

modify_js_file

def modify_js_file(file_path, new_content):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()

        # Check if new content is already included
        if "image_upload_artist" not in content:
            insert_position = content.find('nodeData.input.required.upload = ["IMAGEUPLOAD"];')
            if insert_position != -1:
                insert_position += len('nodeData.input.required.upload = ["IMAGEUPLOAD"];')
                content = content[:insert_position] + new_content + content[insert_position:]

                # Backup the original file
                backup_path = file_path + '.backup'
                with open(backup_path, 'w', encoding='utf-8') as backup_file:
                    backup_file.write(content)

                # Write modified content back to file
                with open(file_path, 'w', encoding='utf-8') as file:
                    file.write(content)
                print(f"File '{file_path}' updated successfully.✅")
            else:
                print("Original code block not found.❌")
        else:
            print("File already contains the necessary modifications.✅")
    except Exception as e:
        print(f"An error occurred: {e}")

modify_wedgets_js_file

def modify_wedgets_js_file(file_path, new_content, new_content_2):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()

        # Check if the file already contains the content to be added
        if "ARTISTS_IMAGEUPLOAD" not in content:
            # Find the position of the original code
            insert_position = content.find('return (display==="slider") ? "slider" : "number"')
            if insert_position != -1:
                # Insert new code after the original code
                insert_position += len('return (display==="slider") ? "slider" : "number"')
                content = content[:insert_position] + new_content + content[insert_position:]

            insert_position_2 = content.find('return { widget: uploadWidget };')
            if insert_position_2 != -1:
                # Insert new code after the original code
                insert_position_2 += len('return { widget: uploadWidget };')
                content = content[:insert_position_2] + new_content_2 + content[insert_position_2:]

                # Backup the original file
                backup_path = file_path + '.backup'
                with open(backup_path, 'w', encoding='utf-8') as backup_file:
                    backup_file.write(content)

                # Write back the file
                with open(file_path, 'w', encoding='utf-8') as file:
                    file.write(content)
                print(f"File '{file_path}' updated successfully.✅")
            else:
                print("Original code block not found.❌")
        else:
            print("File already contains the necessary modifications.✅")
    except Exception as e:
        print(f"An error occurred: {e}")

modify_py_file

def modify_py_file(file_path, new_content, search_line, function_content, search_function):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            lines = file.readlines()

        # Prepare key lines of new content and function content for comparison
        new_content_key_line = new_content.strip().split('\n')[0]
        function_content_key_line = function_content.strip().split('\n')[0]

        # Check if new content already exists
        if new_content_key_line not in "".join(lines):
            for index, line in enumerate(lines):
                if search_line in line:
                    lines.insert(index + 1, new_content)
                    break

        # Check if function modification already exists
        if function_content_key_line not in "".join(lines):
            function_start = False
            for index, line in enumerate(lines):
                if search_function in line:
                    function_start = True
                if function_start and "return None" in line:
                    lines.insert(index, function_content)
                    break

        # Backup the original file
        backup_path = file_path + '.backup'
        with open(backup_path, 'w', encoding='utf-8') as backup_file:
            backup_file.writelines(lines)

        # Write back the modified content
        with open(file_path, 'w', encoding='utf-8') as file:
            file.writelines(lines)
        print(f"File '{file_path}' updated successfully.✅")

    except Exception as e:
        print(f"An error occurred: {e}")

THX for Ur great work.
but the preview images in the blocks are still missed.

@nyukers
Copy link

nyukers commented Sep 26, 2024

File /web/extensions/core/uploadImage.js doesn`t exist really in ComfyUI!

@iamicebomb
Copy link

upgrade to new comfyui and simply modify ArtGallery/init.py
uploadimg_js_file_path = os.path.join(current_dir, '../../web/extensions/core/uploadImage.js')
to
uploadimg_js_file_path = os.path.join(current_dir, '../../web/assets/index-BX11rJu2.js')

wedgets_js_file_path = os.path.join(current_dir, '../../web/scripts/widgets.js')
to
wedgets_js_file_path = os.path.join(current_dir, '../../web/assets/index-exUB01hM.js')

it will work now.

@nyukers
Copy link

nyukers commented Oct 12, 2024

wedgets_js_file_path = os.path.join(current_dir, '../../web/assets/index-exUB01hM.js')

no, ComfyUI hasn't these files in ../../web/assets/.

@iamicebomb
Copy link

Comfyui had upgraded , so must modify other files.

@iamicebomb
Copy link

use "git pull" to upgrade comfyui , and modify artgallery node init.py:

uploadimg_js_file_path = os.path.join(current_dir, '../../web/assets/index-BMC1ey-i.js')

wedgets_js_file_path = os.path.join(current_dir, '../../web/assets/index-DGAbdBYF.js')

it will work now.

@nyukers
Copy link

nyukers commented Oct 13, 2024

UnicodeEncodeError: 'charmap' codec can't encode characters in position 154334-154342: character maps to
I believe that such bad code is not worth for my attention in the future)). Thanks.

@iamicebomb
Copy link

you can try that in init.py modify the open function add "encoding='utf-8'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants