如何安装Python软件包以供所有用户全局使用(包括www-data) [英] How to install Python Package for global use by all users (incl. www-data)

查看:462
本文介绍了如何安装Python软件包以供所有用户全局使用(包括www-data)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我在服务器(Ubuntu 16.04)上放了一个肮脏的脚本,使我从Python输出了一些纯文本.

I thought I throw together a little dirty script on our server (Ubuntu 16.04) that gives me some plain text output from Python.

我想从PHP调用这样的脚本(我知道应该做一些转义,但这只是目前的测试):

I want to call the script like this from PHP (I know there should be some escaping done, but it's just a test currently):

<?php
$command = '/usr/local/bin/script.py';
$output = shell_exec($command);
echo $output;
?>

这是www数据模式774

#!/usr/bin/python
import CoolProp.CoolProp as CP
import argparse
print('Hallo Welt')

如果我注释掉CoolProp导入,它将起作用.但是www-data无法以某种方式到达该程序包,因此脚本不返回任何内容.

If I comment out the CoolProp import it works. But somehow the package cannot be reached by www-dataand so the script returns nothing.

如您所见,我要使用软件包CoolProp.

As you see I want to use the Package CoolProp.

  1. 因此,我尝试使用pip install CoolProp =>安装它,该设置对我的本地用户有效.但是现在当从用户www-data
  2. 调用时
  3. 尝试将其安装到目标--target=/usr/local/lib/site-packages/后,但这没有帮助.
  4. 我试图将完整site-packages/上的ACL更改为rwx 用于www数据,但效果不佳.
  1. So I tried installing it with pip install CoolProp=> That works for my local user. But now when called from user www-data
  2. After I tried to install it with a target --target=/usr/local/lib/site-packages/ but that did not help.
  3. I tried to change the ACL on the complete site-packages/ to rwx for www-data but that does not work as well.

最后:最简单的方法是pip install一个可以供包括www-data在内的所有用户使用的软件包?

In the end: What is the simplest way to pip install a package that can be used by all users including www-data?

推荐答案

我建议您尝试 xotihcan 首先发布的解决方案,因为这是使最高的简便方法> python模块可用于所有用户,包括www-data.但是,它不适用于每个 python模块.如果那对您不起作用,或者您只想为www-data用户安装模块,则使用以下命令:

I recommend that you try the solution that xotihcan posted first as that is the easy way to make most python modules available to all users including www-data. However it doesn't work for every python module. If that doesn't work for you or you just want to install modules for the www-data user only then use the following commands:

sudo mkdir /var/www/.local
sudo mkdir /var/www/.cache
sudo chown www-data.www-data /var/www/.local
sudo chown www-data.www-data /var/www/.cache
sudo -H -u www-data pip install CoolProp

我在尝试使Python pyro4模块可用于www-data时遇到了同样的问题.还有另一种方法可以做到,但是它甚至涉及一些更脏的黑客.有关更多详细信息,请查看我的问题/答案@

I had this same issue trying to make the Python pyro4 module available for the www-data use. There is another way to do it but it involves some even dirtier hackery. For more details check out my question/answer @ How do I properly call a Python Pyro client using PHP and Apache web server?

这篇关于如何安装Python软件包以供所有用户全局使用(包括www-data)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆