Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何写“准确的”字;setup.py“;(入口点)当我想从子包和python包中生成多个命令行应用程序时_Python_Python 3.x_Package_Setuptools - Fatal编程技术网

如何写“准确的”字;setup.py“;(入口点)当我想从子包和python包中生成多个命令行应用程序时

如何写“准确的”字;setup.py“;(入口点)当我想从子包和python包中生成多个命令行应用程序时,python,python-3.x,package,setuptools,Python,Python 3.x,Package,Setuptools,我想根据教程编写一个小型个人软件包:。 目录的结构如下所示: python-cmdline-bootstrap/ ├── docs ├── test ├── bootstrap │ ├── __init__.py │ ├── __main__.py │ ├── bootstrap.py │ └── stuff.py ├── bootstrap-runner.py ├── LICENSE ├── MANIFEST.in ├── README.rst └── setup.py 我进

我想根据教程编写一个小型个人软件包:。 目录的结构如下所示:

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
...
case.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'
回溯(最近一次呼叫最后一次):
文件“/home/chxp/tmp/python3 test/bin/cccase”,第11行,在
加载入口点('cmdline-bootstrap==0.2.0','console\u scripts','cccase')()
文件“/home/chxp/tmp/python3 test/lib/python3.8/site packages/pkg_resources/_init__.py”,第489行,在加载入口点
返回获取分布(dist)。加载入口点(组、名称)
文件“/home/chxp/tmp/python3 test/lib/python3.8/site packages/pkg_resources/_init__.py”,第2852行,在加载入口点
返回ep.load()
文件“/home/chxp/tmp/python3 test/lib/python3.8/site packages/pkg_resources/_init__.py”,第2443行,已加载
返回self.resolve()
文件“/home/chxp/tmp/python3-test/lib/python3.8/site-packages/pkg_-resources/_-init__.py”,第2449行,解析
module=\uuuu导入(self.module\u name,fromlist=[''\uuuu name\uuuuuuu'],级别=0)
ModuleNotFoundError:没有名为“bootstrap.src”的模块
如果我使用
/bootstrap runner.py
python-m bootstrap
,它工作得很好,我认为这可能是
设置.py
中的错误。 因此,如何修改setup.py?我想在python包中生成不同的命令行应用程序

同时,如何在一次运行中使用
/bootstrap runner.py
python-m bootstrap
测试多个命令行应用程序。 似乎我需要更改
\uuu main\uuuuuuuy.py
bootstrap runner.py
中的内容来测试每个命令行应用程序,例如
bootstrap
cccase

原始脚本在“”处上载,并通过git clone下载https://gitee.com/chxp/python-cmdline-bootstrap.git

谢谢你的帮助


我在这里看到了解释:。它完美地回答了我的问题。

我找到了解决办法!如果您指定了
软件包
,则功能
设置
中的
软件包
参数似乎无法识别子模块

因此,以下更改将起作用:

from setuptools import setup, find_packages

setup(
    name="cmdline-bootstrap",
    packages=find_packages(),
    entry_points=console_scripts,
    version=version,
    description="Python command line application bare bones template.",
    long_description=long_descr,
    author="Jan-Philip Gehrcke",
    author_email="jgehrcke@googlemail.com",
    url="http://gehrcke.de/2014/02/distributing-a-python-command-line-application",
)
只需使用
packages=find\u packages()
替换
packages=[“bootstrap”]


但是我仍然不知道如何真正解释这个问题,如果我仍然想使用
包=[“bootstrap”]

如果你不使用
查找包
,你必须自己列出所有包<代码>软件包=[“bootstrap”,“bootstrap.src”]等。查看详细信息。谢谢!我真的知道问题是什么。