‘pip’ is the Package Installer for Python (well, it seems nobody certainly knows what the acronym means, but it fits…). Today, I had to install one utility built in Python language that required some extra library. The INSTALL recipe recommends to install with pip, but you should know how to do it without using the almighty root user. This post is a micro-howto install Python packages with pip in Debian.
The self-learning procedure
Roadrunners: skip to the next header if you are not interested in the hidden details…
First, hands on pretty console:
sudo apt-get install python-pip
Cool! Second, install the Python package:
pip install ino
Uh-oh, red lines are shown and one line explains the reason:
error: could not create '/usr/local/lib/python2.7/dist-packages/ino':
WTF. Must it be run by root? In Debian? I am doing something wrong, so it’s time to do an automatic and hopeless ‘ls’:
ls -la /usr/local/lib/python2.7/dist-packages/
Can you see something strange in that directory entry:
drwxrwsr-x 2 root staff 4096 Jul 5 17:47 .
It’s time to google: “debian staff group /usr/local”. If you do so, you will read the Debian Policy explaining those owner:group and the suid flag in that directory (and others). Basically, users in the ‘staff’ group are enabled to install software under /usr/local as ‘junior sysadmins’.
The user I was managing didn’t belong to the ‘staff’ group.
Enabling the user to install packages with pip
Add the current user (caligari in this case) to the ‘staff’ group:
sudo adduser caligari staff
If you want to postpone the reset of the session in order to bring the group change, use the login command:
sudo login caligari
And, finally, install the package (ino in this case) with the pip command:
pip install ino
Pip, pip, pip, piiiiiiip…