弹性Beanstalk cron导入问题
我使用Elastic Beanstalk检查在cron作业中每小时将时间保存为.txt的代码是否有效 在那之后,我编写了代码,将时间节省为保存爬网结果,但它不起作用 经过一段时间的调试后,似乎出现了一个错误,因为没有安装模块,例如来自bs4 import BeautifulSoup的模块 我该怎么办 我使用的是AL2平台,下面是test.py和cron-linux.config test.py弹性Beanstalk cron导入问题,cron,amazon-elastic-beanstalk,Cron,Amazon Elastic Beanstalk,我使用Elastic Beanstalk检查在cron作业中每小时将时间保存为.txt的代码是否有效 在那之后,我编写了代码,将时间节省为保存爬网结果,但它不起作用 经过一段时间的调试后,似乎出现了一个错误,因为没有安装模块,例如来自bs4 import BeautifulSoup的模块 我该怎么办 我使用的是AL2平台,下面是test.py和cron-linux.config test.py import time from bs4 import BeautifulSoup def func
import time
from bs4 import BeautifulSoup
def function_test():
now = time.strftime('%H%M%S')
now_int = int(now) + 90000 # UTC TO KST 시차가 +9시간 발생
now_kst = now_int % 240000 # 시간은 24시 넘어가면 안되므로 24시간으로 나누어 줌
now_str = str(now_kst).zfill(6)
if 90000 < now_kst and now_kst < 160000:
print("intime")
else:
print("outtime")
f=open('Enterprise.txt','w',encoding='UTF-8')
f.write(now_str)
f.close()
function_test()
当前的.zip配置是
-.ebextensions
>cron-linx.config
-static
-templates
-application.py
-Enterprise.txt
-requirements.txt
-test.py
您可以使用以下方法安装bs4: 您可以使用container_commands键来执行影响应用程序源代码的命令。容器命令在设置应用程序和web服务器并提取应用程序版本存档后,但在部署应用程序版本之前运行 因此,您可以在
.ebextensions
中创建新的配置
例如:
.ebextensions/10_commands.config
container_commands:
10_install_bs4:
command: pip install bs4
20_install_something_else:
command: pip install <other package>
container\u命令:
10\u安装\u bs4:
命令:pip安装bs4
20\u安装\u其他东西\u:
命令:pip-install
requirements.txt-更简单的选择
最简单的方法是将所有pip需求放在应用程序的根文件夹requirements.txt
文件中:
我还有一些问题。如果您还想安装其他模块,command:pip install bs4 command:pip install somemodule我可以添加上述命令吗?我还可以使用命令:pip install bs4==0.0.1吗?有没有一种方法可以像requirements.txt文件那样一次安装模块@김준우 你好是的,requirements.txt
可能更容易。只需将其放在应用程序的根文件夹中。我会更新答案。不知怎的,我忘记了:-)我已经创建并使用了requirements.txt文件@김준우 我不工作?container_命令与cron一起工作,我在我的EB环境中运行它。如何从10_commands.config安装其他模块?
container_commands:
10_install_bs4:
command: pip install bs4
20_install_something_else:
command: pip install <other package>