php - Python Imports 不提供 PHP 中的输出

标签 php python shell

PHP 代码

<?php 
echo shell_exec(' python /Users/rushikesh/Sites/hello2.py ');
>?

Python代码

print('hello')

import numpy as np

print('hello2')

它只输出 hello,为什么代码在 import 语句之后没有给出任何输出。

我什至尝试寻找错误

echo shell_exec(' python /Users/rushikesh/Sites/hello2.py ');

但在导入语句后仍然得到空白输出

最佳答案

putenv('PYTHONPATH=/Users/rushikesh/anaconda3/lib/python3.6/site-packages:');

$command = escapeshellcmd('/Users/rushikesh/anaconda3/bin/python /Users/rushikesh/Sites/hello2.py');


output = shell_exec($command);

echo $output;

从'call python script *with non-standard library imported* from php的答案中找到'

关于php - Python Imports 不提供 PHP 中的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54753059/

相关文章:

python - 如何使用来自 Tensorflow 对象检测 API 的 Mask-RCNN 模型创建自己的数据集?

python - Django 测试 - 如何使用 JSON 发送 HTTP Post Multipart

windows - 用 'sed' 修改后是否需要关闭文件?

linux - 用于将目录结构从源目录复制到目标目录的 Bash 脚本

php - 为什么当密码不正确时,使用 htaccess 进行 http 身份验证会变慢?

php - 闭包重载 : is it possible to inspect the number of arguments a PHP closure has without executing it?

php - 使用 Codeigniter Escape 函数

python - 从模块导入函数在 Python 中如何工作?

python - ManyToManyField 不显示在 Python shell 中

php - 选择所有 MySQL 行并随机重新插入