Python IDE creates folder after which it has no permission to (write or read)

时间:2018-01-11 08:46:30

标签: python permissions pycharm chmod ioerror

In a project I have a function that creates a folder when it doesn't exist yet with the os package.

Now I run into the error then when this folder is created (I run the script with the IDE pycharm) nobody has access, hence the error "IOError: [Errno 13] Permission denied" occurs.

The project runs in a virtual environment, python2.7 and the function is in the gist of:

if not os.path.exists(folder):
   os.makedirs(folder)

What is causing the folder to be inaccessible? Any insights why this is occurring? If I missed any relevant information please let me know.

(changing the permission rights per folder is no solution as the folders need to be created on the fly by user input)

result of folder creation

1 个答案:

答案 0 :(得分:0)

根据documentation,您可以使用以下命令设置目录权限:

os.makedirs(folder, mode=0o777)

请注意,模式不是字符串,而是八进制