Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: __path__ attribute not found on 'guessing_game' while trying to find 'guessing_game.py'

I wrote a simple Python program 'guessing_game.py'. When I try to run this code in the command prompt using python -m guessing_game.py, the program runs fine, but in the end, it says:

Error while finding module specification for 'guessing_game.py'
(ModuleNotFoundError: path attribute not found on 'guessing_game' while trying to find 'guessing_game.py').

When I run the same program using python -guessing_game.py, it runs fine, and it doesn't show that message as well.

like image 414
sbhhdp Avatar asked Oct 27 '25 05:10

sbhhdp


1 Answers

Because you're trying to run it as a module?

From https://docs.python.org/3/using/cmdline.html#cmdoption-m

-m <module-name>

Search sys.path for the named module and execute its contents as the __main__ module.

Since the argument is a module name, you must not give a file extension (.py). The module name should be a valid absolute Python module name, but the implementation may not always enforce this (e.g. it may allow you to use a name that includes a hyphen).

like image 173
jarrey Avatar answered Oct 29 '25 18:10

jarrey