Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 无法从通过Cron-Raspberry-Pi运行的python脚本中执行url_Python 3.x_Raspberry Pi_Python 3.5 - Fatal编程技术网

Python 3.x 无法从通过Cron-Raspberry-Pi运行的python脚本中执行url

Python 3.x 无法从通过Cron-Raspberry-Pi运行的python脚本中执行url,python-3.x,raspberry-pi,python-3.5,Python 3.x,Raspberry Pi,Python 3.5,我可以看到我的代码执行,但chronium浏览器无法打开。你们有谁能帮忙吗?我和你们有同样的问题。您的作业失败,因为它需要,因为您正在尝试打开web浏览器。您应该放置导出显示=:0在cronjob中的计划之后,如中所示 import Datetime import webbrowser import os import time n = datetime.datetime.today().weekday() fo = open("Morning.py","r") if n == 0:

我可以看到我的代码执行,但chronium浏览器无法打开。你们有谁能帮忙吗?我和你们有同样的问题。您的作业失败,因为它需要,因为您正在尝试打开web浏览器。您应该放置
导出显示=:0在cronjob中的计划之后,如中所示

import Datetime
import webbrowser
import os
import time

n = datetime.datetime.today().weekday()

fo = open("Morning.py","r")

if n == 0:

    print('Monday')
    webbrowser.open('https://www.youtube.com',new=0)
    time.sleep(10)
    os.system('pkill chromium')

if n == 1:

    print('Monday')
    webbrowser.open('https://www.youtube.com',new=0)
    time.sleep(10)
    os.system('pkill chromium')

if n == 2:

    print('Monday')
    webbrowser.open('https://www.youtube.com',new=0)
    time.sleep(10)
    os.system('pkill chromium')

if n == 3:

    print('Monday')
    webbrowser.open('https://www.youtube.com',new=0)
    time.sleep(10)
    os.system('pkill chromium')

if n == 4:

    print('Monday')
    webbrowser.open('https://www.youtube.com',new=0)
    time.sleep(10)
    os.system('pkill chromium')

if n == 5:

    print('Monday')
    webbrowser.open('https://www.youtube.com',new=0)
    time.sleep(10)
    os.system('pkill chromium')

if n == 6:

    print('Monday')
    webbrowser.open('https://www.youtube.com',new=0)
    time.sleep(10)
    os.system('pkill chromium')

os.system('pkill chromium')

print('Finish')

fo.close()

Python3 - file executes fine but if I want to schedule to run this code to run every minute, I am using Cron (rasberry pi)

* * * * * cd Desktop && /usr/bin/python3.5m Morning.py >> Output.out
但是请注意,
cd Desktop&&/usr/bin/python3.5m Morning.py
也可能无法与
cron
一起使用。建议将多个命令放入一个
.sh
脚本中,该脚本已被
chmod+x
'd

如果这不起作用,您可以在图形终端中将
:0
替换为
echo$DISPLAY
的输出

* * * * * export DISPLAY=:0; cd Desktop && /usr/bin/python3.5m Morning.py >> Output.out