Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a module for all users with pip on linux?

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 "<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 |                 ||     || 

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 
like image 988
nowox Avatar asked Apr 27 '16 18:04

nowox


People also ask

How do I install pip for all users?

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.

How do you install pip all modules?

You can install modules or packages with the Python package manager (pip). To install a module system wide, open a terminal and use the pip command. If you type the code below it will install the module. That will install a Python module automatically.


2 Answers

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 
like image 91
nowox Avatar answered Oct 07 '22 19:10

nowox


With Ubuntu 18.04, using the command sudo pip install stuff-name does not suffice, in my case, in order to install the modules in the global path (it keeps looking at the local-user python path).

Solution in my case

I have changed to the root user, and changed directory to its home. Then pip installation worked like expected and installs modules in the global path.

In detail I followed the nowox answer with a minor change (sudo su, changes to the root user), also see final note about umask 022:

sudo su cd ~ umask 022 pip install what-you-like 

Note: umask 022 command/row could be optional..., usually umask is already 022, that is the default one.

like image 44
Fabiano Tarlao Avatar answered Oct 07 '22 19:10

Fabiano Tarlao