【发布时间】: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