简体   繁体   中英

Problems with running my python program in Visual Studio

so i wanted to develop a program that converts a png or jpg to a color gradient. i didnt change anything but it keeps spitting out this error. i dont know why i didnt change anything in my visual studio or the main, which is an example from https://www.blog.pythonlibrary.org/2021/02/16/creating-an-image-viewer-with-pysimplegui/


Traceback (most recent call last):
      File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 399, in _handle_exception
        line = linecache.getline(absolute_filename, exc_lineno, check_trace_obj.tb_frame.f_globals)
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\linecache.py", line 30, in getline
        lines = getlines(filename, module_globals)
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\linecache.py", line 46, in getlines
        return updatecache(filename, module_globals)
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\linecache.py", line 137, in updatecache
        lines = fp.readlines()
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\codecs.py", line 322, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdf in position 113: invalid continuation byte
    
During handling of the above exception, another exception occurred:
    
   Traceback (most recent call last):
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
        cli.main()
      File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 444, in main
        run()
      File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 285, in run_file
        runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 269, in run_path
        return _run_module_code(code, init_globals, run_name,
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "C:\Users\MiDy1\source\repos\CHAP\CHAP.py", line 235, in <module>
      File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 189, in trace_exception
        self.handle_user_exception(frame):
      File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 319, in handle_user_exception
        return self._handle_exception(frame, 'exception', exc_info[0], EXCEPTION_TYPE_USER_UNHANDLED)
      File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 402, in _handle_exception
        line = linecache.getline(absolute_filename, exc_lineno)
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\linecache.py", line 30, in getline
        lines = getlines(filename, module_globals)
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\linecache.py", line 46, in getlines
        return updatecache(filename, module_globals)
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\linecache.py", line 137, in updatecache
        lines = fp.readlines()
      File "C:\Users\MiDy1\AppData\Local\Programs\Python\Python310\lib\codecs.py", line 322, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdf in position 113: invalid continuation byte

EDIT:

The problem is that i cant narrow it down. but this is my main() and even that doesnt start:

import glob
import time

import PySimpleGUI as sg
from PIL import Image, ImageTk

    def main():
        elements = [
            [sg.Image(key="originalbild"), sg.Image(key="ergebnisbild")],
            [
                sg.Text("Bildordner: "),
                sg.Input(size=(25, 1), enable_events=True, key="Ordner gewaehlt"),
                sg.FolderBrowse(button_text="Durchsuchen"),
            ],
            [
                sg.Button("Vorheriges Bild"),
                sg.Button("Naechstes Bild")
            ]
        ]
    
        window = sg.Window("CHAP", elements, size=(1000, 475), element_justification='c')
        images = []
        location = 0
    
        while True:
            event, values = window.read()
            if event == "Exit" or event == sg.WIN_CLOSED:
                break
    
            if event == "Ordner gewaehlt":
                images = search_images(values["Ordner gewaehlt"])
                if images:
                    load_image(images[0], window)
                    location = 0
    
            if event == "Naechstes Bild" and images:
                if location == len(images) - 1:
                    location = 0
                else:
                    location += 1
                load_image(images[location], window)
    
            if event == "Vorheriges Bild" and images:
                if location == 0:
                    location = len(images) - 1
                else:
                    location -= 1
                load_image(images[location], window)
    
        window.close()
    
    if __name__ == "__main__":
        main()

Maybe you can help me with this. The line of code where it occurs seems to be: if event == "Exit" or event == sg.WIN_CLOSED: i used the debugging mode and went step by step

i used a 'ß' instead of 'ss'

German problems only

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM