You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS中PowerShell终端运行Python代码无法读取app.png,调试终端正常?

Visual Studio Python PowerShell终端读取图片文件失败问题

在Visual Studio的Python PowerShell终端中运行代码时,出现如下错误:

OSError: Failed to read app.png because file is missing, has improper permissions, or is an unsupported or invalid format

我的代码:

import os
import pyautogui
from pynput.mouse import Button, Controller
import time
import keyboard

import threading
from threading import current_thread
from threading import Thread

import multiprocessing
from multiprocessing import Process, Manager, Queue

from collections import namedtuple

mouse = Controller()
tim = 0.5
time.sleep(3)
ways = os.path.dirname(os.path.abspath(__file__))
conf = 0.70

app = pyautogui.locateCenterOnScreen('app.png' , confidence = (0.70))
print(app)

#pyautogui.move(100, 200)

完整错误信息:

[ WARN:0@1.130] global loadsave.cpp:248 cv::findDecoder imread_('APP.PNG'): can't open/read file: check file path/integrity

Traceback (most recent call last):

File "c: \Users\mathi\OneDrive\Documents\programmation\python\en_cours\wakfu_daily\test.py", line 22, in 
app = pyautogui.locateCenterOnScreen('APP.PNG' , confidence = (0.70))

File "C:\Users\mathi\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui__init__.py", line 172, in wrapper
return wrappedFunction(*args, **kwargs)

File "C:\Users\mathi\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautogui__init__.py", line 204, in locateCenterOnScreen
return pyscreeze.locateCenterOnScreen(*args, **kwargs)

File "C:\Users\mathi\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze__init__.py", line 420, in locateCenterOnScreen
coords = locateOnScreen(image, **kwargs)

File "C:\Users\mathi\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze__init__.py", line 378, in locateOnScreen
retVal = locate(image, screenshotIm, **kwargs)

File "C:\Users\mathi\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze__init__.py", line 356, in locate
points = tuple(locateAll(needleImage, haystackImage, **kwargs))

File "C:\Users\mathi\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze__init__.py", line 205, in _locateAll_opencv
needleImage = _load_cv2(needleImage, grayscale)

File "C:\Users\mathi\AppData\Local\Programs\Python\Python310\lib\site-packages\pyscreeze__init__.py", line 167, in _load_cv2
raise IOError(
OSError: Failed to read APP.PNG because file is missing, has improper permissions, or is an unsupported or invalid format

但代码在以下环境中运行完全正常:

  • Visual Studio调试终端
  • IDLE Python终端
  • Windows Terminal

请问这是扩展、终端、配置还是其他方面的问题?

内容的提问来源于stack exchange,提问作者mushbeck

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 13:28:35