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/