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

查看:52
本文介绍了如何安装 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-data模式774

This is script.py owned by www-data mode 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-data,但效果不佳.
  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 时遇到了同样的问题.还有另一种方法可以做到这一点,但它涉及一些更肮脏的黑客.有关更多详细信息,请查看我的问题/答案@如何使用 PHP 和 Apache Web 服务器正确调用 Python Pyro 客户端?

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天全站免登陆