我需要一些python包装的帮助。我已经知道类似的问题了,但我找不到解决问题的方法。
这是树的输出:
.
├── 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)
__主__吡啶:
def main():
print("hello world")
if __name__ == "__main__":
main()
我做了以下事情:
$ source env/bin/activate
(env) $ python setup.py install
(env) $ ppp
不幸的是我得到了错误,而不是'#hello world'消息:
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'
任何人都可以帮助我展示我错过的内容吗?
答案 0 :(得分:1)
我发现了问题:
在 setup.py 的 entry_points 中,我忘了为 console_settings 设置项目名称:
entry_points = {
'console_scripts': ['ppp=prala.__main__:main'],
},