Making package executable

suggest change

If your package isn’t only a library, but has a piece of code that can be used either as a showcase or a standalone application when your package is installed, put that piece of code into __main__.py file.

Put the __main__.py in the package_name folder. This way you will be able to run it directly from console:

python -m package_name

If there’s no __main__.py file available, the package won’t run with this command. The interpreter prints its own path, then:

No module named package_name.main; 'package_name' is a package and cannot be directly executed.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents