简体   繁体   中英

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.

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  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM