出现这一问题主要是由于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)
再执行就可以了。