crontab错误“ Inforterror:no Module neque request” Python在终端运行正常 - crontab失败
我在一个运行的Python脚本中很难,该脚本将模块称为crontab中的模块。几天前很好,然后我不得不更改Google的身份验证(发送电子邮件),然后“请求”停止在Crontab工作。 Python脚本在终端中运行良好,但不会在crontab中执行。 “请求”可用,当我键入“ pip3 show请求”时显示以下内容(请注意,我用“用户”替换了我的用户名):
$pip3 show requests
Name: requests
Version: 2.27.1
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: [email protected]
License: Apache 2.0
Location: /home/user/.local/lib/python3.6/site-packages
Requires: certifi, idna, urllib3, charset-normalizer
我想在crontab中执行的Python文件的简化版本为:
#!/usr/bin/env python...
# -*- coding: utf-8 -*-
import requests
print ('End of code')
文件< em> test_request.py 在终端中执行良好。
我根据此堆栈溢出页面的方向创建了一个称为 test_request.sh
-no-module-named-requests-in-crontab-python-script“>“ Infrorror:crontab python脚本中no模块name name requests”
脚本是这样的:
#!/bin/bash
echo test_request.sh called: `date`
HOME=/home/user/
PYTHONPATH=/home/user/.local/lib/python3.6/site-packages
cd /home/user/Documents/bjg_code/
python ./test_request.py 2>&1 1>/dev/null
bash 终端或crontab中,我会收到此错误:
$bash test_request.sh
test_request.sh called: Sat Jun 11 14:18:46 EDT 2022
Traceback (most recent call last):
File "./test_request.py", line 4, in <module>
import requests
ImportError: No module named requests
任何建议都将受到欢迎和赞赏。
先感谢您。
I am having difficulty in a running python script that calls module "requests" in crontab. This was fine a few days ago and then I had to change my authentication for Google (to send emails), then "requests" stopped working in crontab. The python script runs fine in a terminal but will not execute in crontab. "requests" is available and when I type "pip3 show requests" the following is displayed (note I replaced my user name with "user"):
$pip3 show requests
Name: requests
Version: 2.27.1
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: [email protected]
License: Apache 2.0
Location: /home/user/.local/lib/python3.6/site-packages
Requires: certifi, idna, urllib3, charset-normalizer
A simplified version of the python file I would like to execute in crontab is:
#!/usr/bin/env python...
# -*- coding: utf-8 -*-
import requests
print ('End of code')
The file test_request.py executes fine in a terminal.
I created a bash script called test_request.sh based on directions from this stack overflow page:
"ImportError: No module named requests" in crontab Python script
That bash script is this:
#!/bin/bash
echo test_request.sh called: `date`
HOME=/home/user/
PYTHONPATH=/home/user/.local/lib/python3.6/site-packages
cd /home/user/Documents/bjg_code/
python ./test_request.py 2>&1 1>/dev/null
When I try to run the bash script in a terminal or in crontab I receive this error:
$bash test_request.sh
test_request.sh called: Sat Jun 11 14:18:46 EDT 2022
Traceback (most recent call last):
File "./test_request.py", line 4, in <module>
import requests
ImportError: No module named requests
Any advice would be welcomed and appreciated.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论