PermissionError:[WinError 5]访问被拒绝Python 3.7 Twitch Bot

2024-04-29 11:35:46 发布

您现在位置:Python中文网/ 问答频道 /正文

这里是新的编码员。搜索了这么多,用谷歌搜索,但我还是被难住了

目标:创建启动pipenv的脚本,以及使用tkinter的自定义twitch机器人

"""dbot_script.py"""
import subprocess
import tkinter as tk
import runpy

root = tk.Tk()

canvas1 = tk.Canvas(root, width=300, height=300)
canvas1.pack()


def activate_dbot():
    subprocess.call([r'C:\Users\user\.virtualenvs\dbot-T1lnEOta'])
    runpy.run_path(r'C:\Users\user\dbot\bot.py')


button1 = tk.Button(text='Activate dbot', command=activate_dbot, bg='brown', fg='white')
canvas1.create_window(150, 150, window=button1)

root.mainloop()

预期结果:pipenv将启动,然后运行bot的tkinter接口将启动

实际结果:Tkinter界面显示按钮,没有显示pipenv启动的迹象。Eror消息:PermissionError:[WinError 5]在终端中访问被拒绝

当我运行时,bot运行正常:

pipenv run python bot.py

在命令行中,但当我试图通过tkinter接口激活它时,我会收到上面所述的错误消息。我也尝试过在管理员模式下运行命令行

我用来连接twitch的模块是twitchio,我可以访问我的oauth密钥

完整错误消息:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Users\user\dbot\dbot_script.py", line 12, in activate_dbot
    subprocess.call([r'C:\Users\user\.virtualenvs\dbot-T1lnEOta'])
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 323, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

Tags: inpytkinterlocalbotpipenvlinecall