为什么 Task Scheduler 运行 我的 Python 脚本不会
Why won't Task Scheduler run my Python Script
我正在尝试 运行 使用任务计划程序的 python 脚本,我已经编写了一个批处理文件;
"C:\Program Files\WinPython64\python-3.7.7.amd64\python.exe" "C:\Users\USER\Documents\Python_Code\Python3.6\Web_Scraping\Firmware_Upgrade\Set_Check_Upgrade_v7.py"
这适用于简单的 Hello World 类型示例。
当我尝试 运行 我的实际代码时,我收到以下错误消息;
C:\Windows\system32>"C:\Program Files\WinPython64\python-3.7.7.amd64\python.exe" "C:\Users\USER\Documents\Python_Code\Python3.6\Web_Scraping\Firmware_Upgrade\Set_Check_Upgrade_v7.py"
DevTools listening on ws://127.0.0.1:53073/devtools/browser/18cef93b-eaa4-4e14-9439-6f0b66b60727
Traceback (most recent call last):
File "C:\Users\USER\Documents\Python_Code\Python3.6\Web_Scraping\Firmware_Upgrade\Set_Check_Upgrade_v7.py", line 22, in <module>
firmware_data = pd.read_excel(total_string)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_base.py", line 824, in __init__
self._reader = self._engines[engine](self._io)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_xlrd.py", line 21, in __init__
super().__init__(filepath_or_buffer)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_xlrd.py", line 36, in load_workbook
return open_workbook(filepath_or_buffer)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\xlrd\__init__.py", line 111, in open_workbook
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'Upgrade_v5.22_01-08-2020.xlsx'
我用过的python代码是
file_string = 'Upgrade_v5.22_01-08-2020'
total_string = file_string + '.xlsx'
firmware_data = pd.read_excel(total_string)
在 Pycharms IDE 中 运行 但不使用 Windows 10 Task Scheduler App 运行 时有效。
Excel 文件与 Python 文件位于同一目录中。
我已经尝试在启用“运行 具有最高权限”的情况下创建任务,但这没有区别。
将您的脚本文件目录添加到 .xlsx 文件名变量。 os.path.dirname(os.path.realpath(__file__))
应该可以解决问题。
我正在尝试 运行 使用任务计划程序的 python 脚本,我已经编写了一个批处理文件;
"C:\Program Files\WinPython64\python-3.7.7.amd64\python.exe" "C:\Users\USER\Documents\Python_Code\Python3.6\Web_Scraping\Firmware_Upgrade\Set_Check_Upgrade_v7.py"
这适用于简单的 Hello World 类型示例。
当我尝试 运行 我的实际代码时,我收到以下错误消息;
C:\Windows\system32>"C:\Program Files\WinPython64\python-3.7.7.amd64\python.exe" "C:\Users\USER\Documents\Python_Code\Python3.6\Web_Scraping\Firmware_Upgrade\Set_Check_Upgrade_v7.py"
DevTools listening on ws://127.0.0.1:53073/devtools/browser/18cef93b-eaa4-4e14-9439-6f0b66b60727
Traceback (most recent call last):
File "C:\Users\USER\Documents\Python_Code\Python3.6\Web_Scraping\Firmware_Upgrade\Set_Check_Upgrade_v7.py", line 22, in <module>
firmware_data = pd.read_excel(total_string)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_base.py", line 824, in __init__
self._reader = self._engines[engine](self._io)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_xlrd.py", line 21, in __init__
super().__init__(filepath_or_buffer)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\pandas\io\excel\_xlrd.py", line 36, in load_workbook
return open_workbook(filepath_or_buffer)
File "C:\Program Files\WinPython64\python-3.7.7.amd64\Lib\site-packages\xlrd\__init__.py", line 111, in open_workbook
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'Upgrade_v5.22_01-08-2020.xlsx'
我用过的python代码是
file_string = 'Upgrade_v5.22_01-08-2020'
total_string = file_string + '.xlsx'
firmware_data = pd.read_excel(total_string)
在 Pycharms IDE 中 运行 但不使用 Windows 10 Task Scheduler App 运行 时有效。
Excel 文件与 Python 文件位于同一目录中。
我已经尝试在启用“运行 具有最高权限”的情况下创建任务,但这没有区别。
将您的脚本文件目录添加到 .xlsx 文件名变量。 os.path.dirname(os.path.realpath(__file__))
应该可以解决问题。