Permission problems when creating a dir with os.makedirs in Python

According to the official python documentation the mode argument of the os.makedirs function may be ignored on some systems, and on systems where it is not ignored the current umask value is masked out.

Either way, you can force the mode to 0o777 (0777 threw up a syntax error) using the os.chmod function.


You are running into problems because os.makedir() honors the umask of current process (see the docs, here). If you want to ignore the umask, you'll have to do something like the following:

import os
try:
    original_umask = os.umask(0)
    os.makedirs('full/path/to/new/directory', desired_permission)
finally:
    os.umask(original_umask)

In your case, you'll want to desired_permission to be 0777 (octal, not string). Most other users would probably want 0755 or 0770.

Tags:

Python