Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locally installed package-ImportError: module '__main__' has no attribute 'main'

Tags:

python-3.x

I need a little help with python packaging. I known similar questions has been already asked, but I could not find the solution for my problem.

Here is the output of tree:

.
├── env
├── prala
│   ├── __init__.py
│   └── __main__.py
└── setup.py

setup.py:

from setuptools import setup, find_packages
setup(
      name='prala',
      version='0.5',
      description='Practice Language',
      url='http://github.com/*/*',
      author='*',
      author_email='*@*.com',
      license='MIT',
      classifiers =[
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
      ],

      packages=find_packages(),
      entry_points = {
        'console_scripts': ['ppp=__main__:main'],
      },
      zip_safe=False)

__main__.py:

def main():
   print("hello world")

if __name__ == "__main__":
    main()

I did the following:

  1. I activated the virtualenv in the root: $ source env/bin/activate
  2. I built the dist and installed it: (env) $ python setup.py install
  3. I run the entry point: (env) $ ppp

Unfortunately I got error instead of the 'hello world' message:

Traceback (most recent call last):
  File "/home/akoel/Projects/python/delete/env/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2332, in resolve
    return functools.reduce(getattr, self.attrs, module)
AttributeError: module '__main__' has no attribute 'main'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/akoel/Projects/python/delete/env/bin/ppp", line 11, in <module>
    load_entry_point('prala==0.5', 'console_scripts', 'ppp')()
  File "/home/akoel/Projects/python/delete/env/lib/python3.6/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/akoel/Projects/python/delete/env/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/home/akoel/Projects/python/delete/env/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/home/akoel/Projects/python/delete/env/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2334, in resolve
    raise ImportError(str(exc))
ImportError: module '__main__' has no attribute 'main'

Can anyone help me showing what did I miss?

like image 533
akoel Avatar asked Sep 15 '25 23:09

akoel


1 Answers

I found the problem:

In the entry_points in the setup.py I forgot to put the project name for the console_settings:

  entry_points = {
    'console_scripts': ['ppp=prala.__main__:main'],
  },
like image 107
akoel Avatar answered Sep 17 '25 15:09

akoel