/project
../project/script.py
../project/__init__.py (This is a blank File)
setup.py
other files like README.
#script.py
def function1():
print "hi"
def main():
function1()
if __name__ == '__main__':
main()
#setup.py
setup(
name='project',
version= __version__,
long_description=markdown_contents,
packages=['project'],
entry_points={
'console_scripts': [ 'project=project:main']
}
)
I am able to to pip install and stuff. but when I run project once the package is installed ,
I get init_.pyc'> has no 'main' attribute
I just want to run the functions in main of script.py when I run project command on the box. What am I doing wrong ?
Your main project package indeed doesn't have a main attribute. project:main means: import main from the project module, and you don't have such an object in __init__.py.
You probably want to refer to project.script:function1 instead. That object does exist.
Best practice is to define a main() function, and use that as an entry point:
def function1():
print "hi"
def main():
function1()
if __name__ == '__main__':
main()
Now you can add more to main() as needed.
Note that the __name__ == '__main__' test will always be false when the script module is imported by the script generated by setuptools. The file is not run directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With