Issue
I've screwed up some permissions in my dist-packages folder for Python 2.7 and am worried it is going to cause issues.
This stems from an entirely separate issue with imports, which caused me to change the permissions of this folder to test things out.
I took the advice to run:
chmod -R 775 /usr/local/lib/python2.7/dist-packages/
.
When this did not work I attempted to change it back to what it was originally with:
chmod 765 /usr/local/lib/python2.7/dist-packages/
Notice the lack of recursive flag. Silly me.
When I did an ls -l
I saw I had permissions of drwxrwSr-x
on the folder. It should be drwxrwsr-x
. So I gave it execute permissions with chmod +x
and then setgid - chmod g+s mydir
Ok, so my folder permissions were now back to normal. However in the folder now I see most (not all) of the files are drwxrwSr-x
.
What should I do to fix this mess? Here is an excerpt from the messy folder contents:
drwxrwSr-x 2 root staff 4096 Jul 19 12:48 wheel-0.30.0.dist-info
drwxrwSr-x 12 root staff 4096 Jul 19 12:48 whoosh
drwxrwSr-x 2 root staff 4096 Jul 19 12:48 Whoosh-2.7.4.dist-info
drwxrwSr-x 2 root staff 4096 Jul 19 12:48 xmltodict-0.11.0.dist-info
-rwxrw-r-x 1 root staff 17356 Jul 19 12:48 xmltodict.py
-rwxrw-r-x 1 root staff 15128 Jul 19 12:48 xmltodict.pyc
drwxrwSr-x 2 root staff 4096 Jul 19 12:48 yaml
-rwxrw-r-x 1 root staff 1115503 Jul 19 12:48 _yaml.so
Solution
There might be shorter ways but I use find
to do a different chmod
on directories than on files. Under dist-packages there are no executable files (at least I have never seen some) so you can do:
find /usr/local/lib/python2.7/dist-packages/ -type d -exec chmod 755 {} +
find /usr/local/lib/python2.7/dist-packages/ -type f -exec chmod 644 {} +
Alternatively you can use 775
for the directory (upper) line and 664
for the files.
There are probably going to be symlinks under dist-packages
(there are on my Debian based system), but their permission setting should not matter.
Answered By - Anthon