python为所有用户安装_如何在Linux上使用pip为所有用户安装模块?

在Linux上使用pip为所有用户安装Python包时遇到权限问题,安装的模块仅对root用户可见。问题在于安装的文件权限只对root和staff组开放。解决方案是调整umask设置,然后卸载并重新安装模块。
摘要由CSDN通过智能技术生成

How to install a package in the standard python environment i.e. /usr/local/lib/python2.7/dist-packages using pip and make this new package available for all the users without using virtualenv?

By using the following, the package is installed with root permissions only:

$ 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...

Proof:

$ python -c 'import loremipsum'

Traceback (most recent call last):

File "", line 1, in

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 |

|| ||

Please do not advise me to use apt-get install python-... instead. I would like to know what is my mistake and how to use pip correctly.

$ 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

EDIT

I guess the problem is because pip does not allow the group and everyone to read the installed stuff:

$ 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

解决方案

You might have a wrong umask set as discussed here

From your last edit, I guess you umask is set to 027. Try to do

sudo pip uninstall loremipsum

umask 022

sudo pip install loremipsum

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值