the difference between os.mkdir() and os.makedirs()

os.makedirs() : Recursive directory creation function. Like os.mkdir(), but makes all intermediate-level directories needed to contain the leaf directory.

What this means is that you should not try to create nested directories with os.mkdir() but use os.makedirs() instead.

In your case, I am guessing that you want to create a directory under your home directory, in which case you would need something like os.mkdir("/home/img"), which will fail if you do not have enough permissions.

You could try and do something like: os.chdir('/home') and after that os.mkdir('img') so you create home/img in steps! Good luck!