简体   繁体   English

来自 crontab 的 bash 脚本中的错误 python 路径

[英]Bad python path in bash script from crontab

I would like to use the python3 executable when I use it from crontab as manual launch (ssh session).当我从 crontab 使用 python3 可执行文件作为手动启动(ssh 会话)时,我想使用它。

bash script bash 脚本

#!/bin/bash

PYTHONPATH="$(which python3)"
echo $PYTHONPATH

python3 test.py

result from ssh command line, launched manually来自 ssh 命令行的结果,手动启动

/usr/local/bin/python3

result in log file from crontab -e从 crontab -e 生成日志文件

/usr/bin/python3

I would like the script launched by the crontab, uses /usr/local/bin/python3 executable instead of /usr/bin/python3我想要由 crontab 启动的脚本,使用/usr/local/bin/python3可执行文件而不是/usr/bin/python3

OR if it's not possible, use the dependencies of my code available for /usr/bin/python3或者,如果不可能,请使用我可用于/usr/bin/python3 的代码的依赖项

How can I achieve this ?我怎样才能做到这一点? Thank you very much for your help非常感谢您的帮助

the python inside the docker container will not necessarily have the same path. docker 容器内的 python 不一定具有相同的路径。 If you want all the modules installed on your VM python3, create a requirements.txt file using pip freeze > requirements.txe and COPY this file as part of your Dockerfile and install it while building the image pip install -r requirements.txt如果您希望将所有模块安装在您的 VM python3 上,请使用pip freeze > requirements.txe创建一个 requirements.txt 文件并将此文件作为 Dockerfile 的一部分复制并在构建映像时安装它pip install -r requirements.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM