After running the above code, I got the following error:
File "C:/Users/yat/test.py", line 9, in <module> import posix ImportError: No module named posix
When I tried
pip install posix
, I got the following message:
Collecting posix Could not find a version that satisfies the requirement posix (from versions) No matching distribution found for posix`
Just replace posix with os in code.
That's a built-in module that's not available on Windows. Look at the documentation:
Do not import this module directly. Instead, import the module os, which provides a portable version of this interface. On Unix, the os module provides a superset of the posix interface. On non-Unix operating systems the posix module is not available, but a subset is always available through the os interface. Once os is imported, there is no performance penalty in using it instead of posix. In addition, os provides some additional functionality, such as automatically calling os.putenv when an entry in os.environ is changed.
So just replace posix with os and you should be good to go.