gpt4 book ai didi

python - 如何在 linux 上为所有使用 pip 的用户安装模块?

转载 作者:IT老高 更新时间:2023-10-28 20:25:33 26 4
gpt4 key购买 nike

如何在标准 python 环境中安装包 /usr/local/lib/python2.7/dist-packages 使用pip 并在不使用 virtualenv 的情况下让所有用户都可以使用这个新包?

通过使用以下内容,软件包仅以 root 权限安装:

$ sudo pip install loremipsum
Downloading/unpacking loremipsum
Downloading loremipsum-1.0.5.tar.gz
Running setup.py (path:/tmp/pip_build_root/loremipsum/setup.py)
egg_info for package loremipsum

Installing collected packages: loremipsum
Running setup.py install for loremipsum

Successfully installed loremipsum
Cleaning up...

证明:

$ python -c 'import loremipsum'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named loremipsum

$ sudo python -c 'import loremipsum'

$ pip install loremipsum
Requirement already satisfied (use --upgrade to upgrade): loremipsum in
/usr/local/lib/python2.7/dist-packages
Cleaning up...

$ cowsay sad
_____
< sad >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

请不要建议我改用 apt-get install python-...。我想知道我的错误是什么以及如何正确使用 pip。

$ python --version
Python 2.7.6
$ pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
$ uname -a
Linux _ 3.19.0-32-generic #37~14.04.1-Ubuntu SMP _ x86_64 GNU/Linux

编辑

我猜这个问题是因为pip不允许组和大家阅读安装的东西:

$ sudo pip uninstall loremipsum
Uninstalling loremipsum:
/usr/local/lib/python2.7/dist-packages/loremipsum-1.0.5.egg-info
/usr/local/lib/python2.7/dist-packages/loremipsum/__init__.py
/usr/local/lib/python2.7/dist-packages/loremipsum/__init__.pyc
/usr/local/lib/python2.7/dist-packages/loremipsum/default/dictionary.txt
/usr/local/lib/python2.7/dist-packages/loremipsum/default/sample.txt
/usr/local/lib/python2.7/dist-packages/loremipsum/generator.py
/usr/local/lib/python2.7/dist-packages/loremipsum/generator.pyc
Proceed (y/n)? y
Successfully uninstalled loremipsum

$ sudo pip install loremipsum
Downloading/unpacking loremipsum
Downloading loremipsum-1.0.5.tar.gz
Running setup.py (path:/tmp/pip_build_root/loremipsum/setup.py)
egg_info for package loremipsum

Installing collected packages: loremipsum
Running setup.py install for loremipsum

Successfully installed loremipsum
Cleaning up...
$ sudo ls -al /usr/local/lib/python2.7/dist-packages/loremipsum
total 60
drwxr-s--- 3 root staff 4096 Apr 27 22:06 .
drwxrwsr-x 18 root staff 4096 Apr 27 22:06 ..
drwxr-s--- 2 root staff 4096 Apr 27 22:06 default
-rw-r----- 1 root staff 16182 Apr 27 22:06 generator.py
-rw-r----- 1 root staff 16323 Apr 27 22:06 generator.pyc
-rw-r----- 1 root staff 6130 Apr 27 22:06 __init__.py
-rw-r----- 1 root staff 6869 Apr 27 22:06 __init__.pyc

最佳答案

您可能设置了错误的 umask,如所讨论的 here

从您上次的编辑来看,我猜您的 umask 设置为 027。努力去做

sudo pip uninstall loremipsum
umask 022
sudo pip install loremipsum

关于python - 如何在 linux 上为所有使用 pip 的用户安装模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36898474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com