gpt4 book ai didi

python-3.x - 本地安装包-ImportError : module '__main__' has no attribute 'main'

转载 作者:行者123 更新时间:2023-12-05 06:35:11 25 4
gpt4 key购买 nike

我需要一些关于 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)

__main__.py:

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

if __name__ == "__main__":
main()

我做了以下事情:

  1. 我在根目录中激活了 virtualenv:$ source env/bin/activate
  2. 我构建了 dist 并安装了它:(env) $ python setup.py install
  3. 我运行入口点:(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'

谁能帮我展示我错过了什么?

最佳答案

我发现了问题:

setup.pyentry_points 中,我忘记输入 console_settings 的项目名称:

  entry_points = {
'console_scripts': ['ppp=prala.__main__:main'],
},

关于python-3.x - 本地安装包-ImportError : module '__main__' has no attribute 'main' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49815721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com