简体   繁体   English

在 Visual Studio 中运行我的 python 程序时出现问题

[英]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.所以我想开发一个将 png 或 jpg 转换为颜色渐变的程序。 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/我不知道为什么我没有在我的视觉工作室或主程序中更改任何内容,这是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:但这是我的 main() 甚至没有开始:

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它发生的代码行似乎是: if event == "Exit" or event == sg.WIN_CLOSED:我使用了调试模式,一步一步走

i used a 'ß' instead of 'ss'我使用了“ß”而不是“ss”

German problems only仅限德国问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Visual Studio Code 中的参数运行 Python 程序 - Running a Python program with arguments from within the Visual Studio Code python 项目未在 Visual Studio 中运行 - python project is not running in visual studio Python应用程序未在Visual Studio中运行 - Python Application not running in visual studio 在Visual Studio 2017中运行python - Running python in Visual Studio 2017 使用srvany.exe运行python程序时出现问题 - Problems running python program with srvany.exe 为Visual Studio 2010安装python工具时出现问题 - Problems with installing python tools for visual studio 2010 在 Python / Visual Studio Code 中安装模块的问题 - Problems with installing modules in Python / Visual Studio Code 在再次运行 python 程序之前,每次都必须在 Visual Studio 代码终端中键入 exit() 吗? - Have to type exit() every time in visual studio code terminal before running python program again? 我的 python 程序中的 for 循环未运行 - For loop in my python program not running 我的代码在python shell中运行良好,但在我的Visual Studio代码上运行它时没有显示任何内容 - My code works fine inside the python shell, but not showing anything when running it on my Visual studio code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM