简体   繁体   English

[Linux,Ubuntu]:使用不同的用户执行Python脚本会导致不同的行为

[英][Linux, Ubuntu]: Executing a Python script with different users results in different behaviours

I'm trying to execute a script in Ubuntu with Python with my user "ubuntu". 我正在尝试用我的用户“ubuntu”在Python中用Ubuntu执行脚本。 It's a virtual machine of Amazon, so I'm trying to execute that code 它是亚马逊的虚拟机,所以我正在尝试执行该代码

$execQuery = "python script.py";
exec($execQuery, $output, $return);

by executing that command with ubuntu the results is OK , but executing it from PHP (which user is www-data ), I get: 通过执行与Ubuntu该命令的结果是好的 ,但是从PHP执行它(该用户WWW的数据 ),我得到:

ImportError: No module named skimage.io ImportError:没有名为skimage.io的模块

So I think there's an error about permission, but since I've never used Python, I don't know where I have to put the right permissions. 所以我认为关于权限有一个错误,但由于我从未使用过Python,我不知道我必须在哪里提供正确的权限。

Does anyone have a clue? 有人有线索吗?

Thank you very much. 非常感谢你。


I've tried to use pip install ___ --user www-data but didn't work either. 我试过使用pip install ___ --user www-data但是也pip install ___ --user www-data

Well, this is weird, while it was working from the main user, it wasn't working from www-data . 嗯,这很奇怪,虽然它是从主要用户开始工作的,但它不能用于www-data

The problem, obviously was in the sckit-image Python module and I thought it was a permission problem . 问题,显然是在sckit-image Python模块中,我认为这是一个权限问题 In fact, the www-data user wasn't locating the right library even if I set the $PYTHONPATH and y tried to import it as well from the script as: 事实上,即使我设置了$PYTHONPATH并且y尝试从脚本中导入它, www-data用户也找不到正确的库:

import sys
sys.path.insert(0, "path/to/python");

but nothing happened. 但什么都没发生。

When installing the scikit-image. 安装scikit-image时。 There was an error on the scipy which was giving me at the same time an error with gfortran . scipy上有一个错误,它同时给了我gfortran的错误。

sudo apt-get install gfortran and reinstalling scipy and scikit-image resolved the problem. sudo apt-get install gfortran并重新安装scipyscikit-image解决了这个问题。

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

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