我想根据教程编写一个小型个人软件包:https://gehrcke.de/2014/02/distributing-a-python-command-line-application/。 目录的结构如下所示:
python-cmdline-bootstrap/
├── docs
├── test
├── bootstrap
│ ├── __init__.py
│ ├── __main__.py
│ ├── bootstrap.py
│ └── stuff.py
├── bootstrap-runner.py
├── LICENSE
├── MANIFEST.in
├── README.rst
└── setup.py
我进一步在引导折叠下添加了一个新模块(src
)和脚本(case.py
),如下所示:
python-cmdline-bootstrap/
...
├── bootstrap
│ ├── __init__.py
│ ├── __main__.py
│ ├── bootstrap.py
│ ├── stuff.py
│ ├── src
│ ├── __init__.py
│ ├── case.py
├── bootstrap-runner.py
...
{
# -*- coding: utf-8 -*-
import argparse
def case():
print("This a new command.")
我将以下行添加到setup.py中:
console_scripts = """
[console_scripts]
bootstrap = bootstrap.bootstrap:main
cccase = bootstrap.src.case:case
"""
安装后在终端中执行python setup.py install
并运行cccase
时,显示错误:
Traceback (most recent call last):
File "/home/chxp/tmp/python3-test/bin/cccase", line 11, in <module>
load_entry_point('cmdline-bootstrap==0.2.0', 'console_scripts', 'cccase')()
File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
return ep.load()
File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2443, in load
return self.resolve()
File "/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2449, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'bootstrap.src'
如果我使用./bootstrap-runner.py
或python -m bootstrap
,它可以正常工作,我认为它可能是setup.py
中的错误。
因此,如何修改setup.py?我想在python包中生成不同的命令行应用程序
同时,如何在一次运行中使用./bootstrap-runner.py
或python -m bootstrap
测试多个命令行应用程序。
似乎我需要更改__main__.py
或bootstrap-runner.py
中的内容来测试每个命令行应用程序,例如bootstrap
、cccase
原始脚本在“https://gitee.com/chxp/python-cmdline-bootstrap”上传,在^{
谢谢你的帮助
我在这里看到了解释:Why do I need to include sub-packages in setup.py。它完美地回答了我的问题
我找到了解决办法!如果指定
packages
,函数setup
中的packages
参数似乎无法识别子模块因此,以下更改将起作用:
只需使用
packages=find_packages()
替换packages=["bootstrap"]
但是我仍然不知道如何真正解释这个问题,如果我仍然想使用^{,我需要做什么
相关问题 更多 >
编程相关推荐