我试图从PHP文件调用Python脚本,但当我必须加载本地库时,它失败了。我的PHP可以调用python,如果它不加载本地库,我的python脚本在手动启动时可以工作。在
以下是最小(非)工作文件:
index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<?php
$command = escapeshellcmd ("./getter.py") ;
$output = shell_exec ($command) ;
echo "<p>$output</p>" ;
?>
</body>
</html>
getter.py
其中got
是当地著名的图书馆。在
当我手动启动我的./getter.py
时,打印正在进行,但我的网页没有显示任何内容。
当我评论import got
时,网页也显示了打印内容。在
附加信息:
os
、csv
或其他)时没有问题$output = shell_exec ("./getter.py") ;
替换$command = escapeshellcmd ("./getter.py") ; $output = shell_exec ($command) ;
#!/usr/bin/python2
替换#!/usr/bin/env python2
/var/html/www/test
中。在以下是文件夹树:
├── getter.py
├── got
│ ├── __init__.py
│ ├── manager
│ │ ├── __init__.py
│ │ ├── TweetCriteria.py
│ │ └── TweetManager.py
│ └── models
│ ├── __init__.py
│ └── Tweet.py
├── index.php
├── __init__.py
└── lib
├── __init__.py
└── toto.py
非常感谢。在
这实际上是由依赖关系问题引起的。某些用户只需要安装一些库。Nginx不能作为根用户访问它,而普通用户可以。在
相关问题 更多 >
编程相关推荐