I encountered this error while running a Python script from Cocos Creator even though the script itself was valid. Restarting Cocos Creator fixed it.
Python 3 had been installed while the editor was already open. A running process keeps the environment it inherited at launch, so Cocos Creator did not see the newly updated PATH. Restarting the editor caused it to load the current environment variables.
If restarting does not help, run python3 --version from the same shell used to start the editor, verify the executable path, and inspect the command’s captured error output.