Python Crontab项导致未知命令

Python Crontab项导致未知命令,python,linux,python-3.x,crontab,Python,Linux,Python 3.x,Crontab,条目 0 * * * * /home/ec2-user/python-scripts/master.py 正在导致以下错误: sh: python3: command not found 我的脚本顶部有一个shebang: #!/usr/local/bin/python3 我认为python3的路径是正确的: [ec2-user@ip-152-31-33-105 cron.hourly]$ /usr/local/bin/python3 Python 3.4.3 (default, Mar

条目

0 * * * *  /home/ec2-user/python-scripts/master.py
正在导致以下错误:

sh: python3: command not found
我的脚本顶部有一个shebang:

#!/usr/local/bin/python3
我认为python3的路径是正确的:

[ec2-user@ip-152-31-33-105 cron.hourly]$ /usr/local/bin/python3
Python 3.4.3 (default, Mar 17 2016, 20:37:33) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
根据建议,我寻找CR,但没有发现:

0000000 23 21 2f 75 73 72 2f 6c 6f 63 61 6c 2f 62 69 6e
0000020 2f 70 79 74 68 6f 6e 33 0a 0a 69 6d 70 6f 72 74
0000040 20 6f 73 0a 0a 64 65 66 20 65 78 74 72 61 63 74
0000060 28 29 3a 0a 20 20 6f 73 2e 73 79 73 74 65 6d 28
0000100 22 70 79 74 68 6f 6e 33 20 63 6c 69 6e 74 6f 6e
0000120 5f 74 77 65 65 74 73 2e 70 79 22 29 20 20 0a 20
0000140 20 6f 73 2e 73 79 73 74 65 6d 28 22 70 79 74 68
0000160 6f 6e 33 20 63 72 75 7a 5f 74 77 65 65 74 73 2e
0000200 70 79 22 29 0a 20 20 6f 73 2e 73 79 73 74 65 6d
0000220 28 22 70 79 74 68 6f 6e 33 20 6b 61 73 69 63 68
0000240 5f 74 77 65 65 74 73 2e 70 79 22 29 0a 20 20 6f
0000260 73 2e 73 79 73 74 65 6d 28 22 70 79 74 68 6f 6e
0000300 33 20 73 61 6e 64 65 72 73 5f 74 77 65 65 74 73
0000320 2e 70 79 22 29 20 0a 20 20 6f 73 2e 73 79 73 74
0000340 65 6d 28 22 70 79 74 68 6f 6e 33 20 74 72 75 6d
0000360 70 5f 74 77 65 65 74 73 2e 70 79 22 29 0a 20 20
0000400 72 65 74 75 72 6e 20 31 0a 0a 65 78 74 72 61 63
0000420 74 28 29 0a 0a
0000425
我应该试试什么


谢谢

请确保行尾不包含回车,只包含新行

od -t x1 /home/ec2-user/python-scripts/master.py
# If there's 0d in the output, it's a carriage return (\r, CR)
如果有回车符,字符也被视为可执行路径的一部分


要删除CR,可以使用类似于
dos2unix
的工具

如果不想使用
dos2unix
,可以使用python:

$ /usr/local/bin/python3 -c \
'f = open("/home/ec2-user/python-scripts/master.py", "r+b"); \
s = f.read().replace(b"\r", b""); f.seek(0); f.write(s); f.close()'

不,谢谢你的邀请suggestion@Slinky,如果直接在shell中运行脚本,它是否工作?是的,我可以从shell提示符运行:[ec2]-user@ip-172-31-33-105 python scripts]$/home/ec2 user/python scripts/master.py我想问题就在这里,在脚本本身:os.system(“python3-trump_-tweets.py”)我将尝试预先设置完整路径。抱歉,问题不包括此部分。我接受你的回答,因为考虑到这个问题,我认为你的解决方案是正确的。Thanks@Slinky,然后,将该部分替换为
os.system(“%s trump\u tweets.py”%sys.executable)
以避免重复同一路径两次。仅供参考。