python: itchat 报错 OSError: 找不到应用程序: 'QR.png'

本文介绍了一种解决在Windows系统下使用itchat登录微信时,二维码无法正常弹出的方法。通过修改itchat的utils.py文件中的print_qr函数,使二维码能在浏览器中打开,从而实现微信的正常登录。

出现这一问题主要是由于windows系统无法打开弹出的登录微信的二维码,原因在于itchat没有对象的处理方法。

1.找到python中itchat的安装路径 

<1>找不到的话 可以再重新安装一下:‘pip install itcaht‘

控制台就会弹出已经安装的提示,下面的路径就是itchat的安装路径

Requirement already satisfied: itchat in e:\my_code\venv\lib\site-packages (1.3.10)

<2>或者使用 pip show itcaht  也会返回安装路径

2.找到 utils.py文件,修改代码

找到 '\Lib\site-packages\itchat\utils.py'

修改其中的 print_qr()函数

#  原函数

#def print_qr(fileDir):
#    if config.OS == 'Darwin':
#        subprocess.call(['open', fileDir])
#    elif config.OS == 'Linux':
#        subprocess.call(['xdg-open', fileDir])
#    else:
#        os.startfile(fileDir)

 

# 修改之后的函数

import webbrowser
def print_qr(fileDir):
    if config.OS == 'Darwin':
        subprocess.call(['open', fileDir])
    elif config.OS == 'Linux':
        subprocess.call(['xdg-open', fileDir])
    elif config.OS =='Windows':
        #默认在ie浏览器打开二维码
        webbrowser.open(fileDir)
        #如果ie浏览器不能打开可以使用一下代码
        file_path = os.path.join(os.getcwd(),fileDir)
        chrome_path = r'C:\Users\PC\AppData\Local\Google\Chrome\Application\chrome.exe'
        webbrowser.register('chrome',None,webbrowser.BackgroundBrowser(chrome_path))
        webbrowser.get('chrome').open_new_tab(file_path)
    else:
        os.startfile(fileDir)

再执行就可以了。

 

1、Umi-OCR未生成结果文件 2、以下是全部日志PS D:\Tool\Tool_python> & C:/Users/chen.yang/AppData/Local/Microsoft/WindowsApps/python3.13.exe d:/Tool/Tool_python/svn_subrepo.py usage: Umi-OCR [-h] [--show] [--hide] [--quit] [--screenshot] [--clipboard] [--path] [--qrcode_create] [--qrcode_read] [--reload] [--all_pages] [--add_page ADD_PAGE] [--del_page DEL_PAGE] [--all_modules] [--call_py CALL_PY] [--call_qml CALL_QML] [--func FUNC] [--thread] [--clip] [--output OUTPUT] [--output_append OUTPUT_APPEND] [--> >] [-->> >>] [paras [paras ...]] positional arguments: paras parameters of [--func]. optional arguments: -h, --help show this help message and exit --show Make the app appear in the foreground. --hide Hide app in the background. --quit Quit app. --screenshot Screenshot OCR and output the result. --clipboard Clipboard OCR and output the result. --path OCR the image in path and output the result. --qrcode_create Create a QR code from the text. Use --qrcode_create "text" "save_image.jpg" --qrcode_read Read the QR code. Use --qrcode_read "image_to_recognize.jpg" --reload Reload settings from the configuration file ".settings" --all_pages Output all template and page information. --add_page ADD_PAGE usage: Umi-OCR --all_pages --del_page DEL_PAGE usage: Umi-OCR --all_pages --all_modules Output all module names that can be called. --call_py CALL_PY Calling a function on a Python module. --call_qml CALL_QML Calling a function on a Qml module. --func FUNC The name of the function to be called. --thread The function will be called on the child thread and return the result, but it may be unstable or cause QML to crash. --clip Copy the results to the clipboard. --output OUTPUT The path to the file where results will be saved. (overwrite) --output_append OUTPUT_APPEND The path to the file where results will be saved. (append) --> > "-->" equivalent to "--output" -->> >> "-->>" equivalent to "--output_append" Your argv: ['ocr', 'C:\\Users\\CHEN~1.YAN\\AppData\\Local\\Temp\\ocr_temp_e76300e0.png', '--lang', 'ch', '--out', 'C:\\Users\\CHEN~1.YAN\\AppData\\Local\\Temp\\ocr_result_e76300e0.json'] [Error]: 2 usage: Umi-OCR --help Fatal Python error: init_sys_streams: can't initialize sys standard streams Python runtime state: core initialized OSError: [WinError 6] 蜿・譟・裏謨医 Current thread 0x00001824 (most recent call first): <no Python frame> Your argv: ['ocr', 'C:\\Users\\CHEN~1.YAN\\AppData\\Local\\Temp\\ocr_temp_e668da49.png', '--lang', 'ch_tra', '--out', 'C:\\Users\\CHEN~1.YAN\\AppData\\Local\\Temp\\ocr_result_e668da49.json'] [Error]: 2 usage: Umi-OCR --help
最新发布
12-02
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值