Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python -m: Error while finding module specification

According to the python doc the -m flag should do the following:

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

When I run my script simply with the python command, everything works fine. Since I now want to import something from a higher level, I have to run the script with python -m. However the __name__ == "__main__" statement seems to return False and the following Error is produced:

/home/<name>/anaconda3/bin/python: Error while finding module specification for 'data.generate_dummies.py' (AttributeError: module 'data.generate_dummies' has no attribute '__path__')

I dont't understand what the __path__ attribute has to do with that.

like image 727
McLawrence Avatar asked Aug 14 '17 05:08

McLawrence


1 Answers

The error you get occurs when python tries to look for a package/module that does not exist. As user2357112 mentions, data.generate_dummies.py is treated as a fully specified module path (that does not exist), and an attempt is made to import a submodule py (that is also non-existent).

Invoke your file without .py, if you're using the -m flag, like this:

python -m data.generate_dummies  
like image 72
cs95 Avatar answered Sep 27 '22 17:09

cs95