[英]Running a Python program with arguments from within the Visual Studio Code
[英]Problems with running my python program in Visual Studio
所以我想開發一個將 png 或 jpg 轉換為顏色漸變的程序。 我沒有改變任何東西,但它一直吐出這個錯誤。 我不知道為什么我沒有在我的視覺工作室或主程序中更改任何內容,這是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
編輯:
問題是我無法縮小范圍。 但這是我的 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()
也許你可以幫我解決這個問題。 它發生的代碼行似乎是: if event == "Exit" or event == sg.WIN_CLOSED:
我使用了調試模式,一步一步走
我使用了“ß”而不是“ss”
僅限德國問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.