简体   繁体   English

如何在php-fpm shell_exec中激活anaconda环境?

[英]How to activate anaconda environment in php-fpm shell_exec?

I have php-fpm running as nginx user in a docker container.我在 docker 容器中以 nginx 用户身份运行 php-fpm。 Dockerfile creates correct anaconda environment called 'ss' with pandas package. Dockerfile 使用 pandas ZEFE90A8E604A7C840D88D03A7C840D88D033A7C840D88D0创建正确的 anaconda 环境,称为“ss”。 It works ok when I attach to the docker container.当我连接到 docker 容器时,它工作正常。

Docker CMD runs an init.sh script: Docker CMD 运行 init.sh 脚本:

. /opt/conda/etc/profile.d/conda.sh
conda activate /opt/conda/envs/ss
php-fpm --fpm-config /etc/php-fpm.conf
nginx -g 'daemon off;'

Then, a PHP script runs Python script using然后,一个 PHP 脚本运行 Python 脚本使用

shell_exec("python ss.py");

This errors with:这与以下错误有关:

ImportError: No module named pandas ImportError:没有名为 pandas 的模块

I tried various combinations of shell_exec where I tried activating the env before running the script, but it mostly errors out with:我尝试了 shell_exec 的各种组合,我尝试在运行脚本之前激活 env,但它大多出错:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate' CommandNotFoundError:您的 shell 尚未正确配置为使用“conda activate”

How do I activate the 'ss' env for all PHP shell_exec scripts?如何为所有 PHP shell_exec 脚本激活“ss”环境?

you can directly use like this.你可以像这样直接使用。

shell_exec('/root/.conda/envs/my-rdkit-env/bin/python3 ss.py'); shell_exec('/root/.conda/envs/my-rdkit-env/bin/python3 ss.py');

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

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