In general, the solution here is to leave foobar.py
as a module, and have the script be something as simple as:
import foobar
foobar.main()
If you're installing your module using setup.py
(and you probably should be), you can also do this via console_scripts
entry points, like this:
entry_points={
'console_scripts': [
'foobar = foobar:main'
],
},
This will install a foobar
command that is roughly equivalent to the stub in the first part of this answer.