pip permission denied…

Have you ever seen the message like this on terminal while installing Python library? Sure!

$ pip install dnspython
Collecting dnspython
 Downloading https://files.pythonhosted.org/packages/a6/72/209e18bdfedfd78c6994e9ec96981624a5ad7738524dd474237268422cb8/dnspython-1.15.0-py2.py3-none-any.whl (177kB)
 100% |████████████████████████████████| 184kB 1.3MB/s 
Installing collected packages: dnspython
Traceback (most recent call last):
 File "/usr/local/lib/python3.4/dist-packages/pip/basecommand.py", line 215, in main
 status = self.run(options, args)
 File "/usr/local/lib/python3.4/dist-packages/pip/commands/install.py", line 342, in run
 File "/usr/local/lib/python3.4/dist-packages/pip/req/req_set.py", line 784, in install
 File "/usr/local/lib/python3.4/dist-packages/pip/req/req_install.py", line 851, in install
 self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
 File "/usr/local/lib/python3.4/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
 File "/usr/local/lib/python3.4/dist-packages/pip/wheel.py", line 345, in move_wheel_files
 clobber(source, lib_dir, True)
 File "/usr/local/lib/python3.4/dist-packages/pip/wheel.py", line 316, in clobber
 File "/usr/local/lib/python3.4/dist-packages/pip/utils/__init__.py", line 83, in ensure_dir
 File "/usr/lib/python3.4/os.py", line 237, in makedirs
 mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.4/dist-packages/dnspython-1.15.0.dist-info'

Hey it’s permission denied here, why not use sudo? No! don’t, just don’t give root permission to random code from internet, even if it’s well know library.

Why not run it under particular user and at least make it more secure by fitting code execution (setup.py) to some “user permission boundary”?

pip install dnspython --user
Collecting dnspython
 Using cached https://files.pythonhosted.org/packages/a6/72/209e18bdfedfd78c6994e9ec96981624a5ad7738524dd474237268422cb8/dnspython-1.15.0-py2.py3-none-any.whl
Installing collected packages: dnspython
Successfully installed dnspython-1.15.0

Typing the same number of characters 🙂 (four chars in sudo and user), but making difference to overall security of system.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s