【问题标题】:Make Python module available for all Linux users使 Python 模块可供所有 Linux 用户使用
【发布时间】:2020-10-26 15:57:46
【问题描述】:

如果有人可以提供帮助,我有一个 Python 2.7 问题。 当我们使用 pip 安装 Python 模块时,我们如何使其对所有用户可用?请参阅下面的示例(使用模块 faker)。当我是 root 时,导入工作,但当我是 ubuntu 用户时,导入不起作用。 我已经尝试使用选项--system 进行安装,并按照我发现的一些文章中的建议更改了 umask。到目前为止没有工作。有任何想法吗? 如果我们运行“which python”,两个用户都指向同一个。

root@ip-172-30-244-157:/home/ubuntu# 
root@ip-172-30-244-157:/home/ubuntu# python
Python 2.7.17 (default, Sep 30 2020, 13:38:04) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import faker
>>> 
>>> exit()
root@ip-172-30-244-157:/home/ubuntu# 
root@ip-172-30-244-157:/home/ubuntu# 
root@ip-172-30-244-157:/home/ubuntu# exit
exit
ubuntu@ip-172-30-244-157:~$ 
ubuntu@ip-172-30-244-157:~$ 
ubuntu@ip-172-30-244-157:~$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import faker
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named faker
>>> 

【问题讨论】:

  • 你能以 root 身份运行它吗:python -c 'import faker; print faker.__file__'
  • root@ip-172-30-244-157:/home/ubuntu# python -c 'import faker;打印 faker.__file__' /usr/local/lib/python2.7/dist-packages/faker/__init__.pyc
  • 当您从 ubuntu 用户运行 @GeorgesMartin 命令时会发生什么?
  • ubuntu@ip-172-30-244-157:~$ python -c 'import faker; print faker.__file__' Traceback(最近一次调用最后一次):文件“”,第 1 行,在 ImportError: No module named faker
  • 您必须考虑使用virtualenv。你试过pip install fake --user ubuntu吗?

标签: python python-2.7 pip ubuntu-18.04 faker


【解决方案1】:

好的,我解决了这个问题。 就我而言,有问题的模块是“假的”。但是,当我们安装 faker 时,还会安装另一个附加模块(在本例中为 text-unidecode)。 然后我卸载了这两个模块,运行“umask 022”并重新安装了faker。 这解决了所有其他用户的问题。 感谢大家的帮助!

【讨论】:

猜你喜欢
  • 2022-07-02
  • 2016-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-21
  • 2018-11-10
  • 2022-06-29
相关资源
最近更新 更多