Python包;点击";原因“;错误:获取了意外的额外参数(sdist bdist_wheel)";在新包装中使用时
我正在尝试创建一个可以用作终端命令的Python包。我的setup.py文件看起来像Python包;点击";原因“;错误:获取了意外的额外参数(sdist bdist_wheel)";在新包装中使用时,python,package,click,python-wheel,Python,Package,Click,Python Wheel,我正在尝试创建一个可以用作终端命令的Python包。我的setup.py文件看起来像 import setuptools # If the package is being updated (and not installed for the first time), # save user-defined data. try: import checklist update = True except ModuleNotFoundError: update = Fal
import setuptools
# If the package is being updated (and not installed for the first time),
# save user-defined data.
try:
import checklist
update = True
except ModuleNotFoundError:
update = False
if update:
import os
import pickle
dir = os.path.join(os.path.dirname(checklist.__file__), 'user_settings')
files = {}
for file in os.listdir(dir):
files[file] = pickle.load(open(os.path.join(dir, file), "rb"))
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="SampleName",
version="0.2.0",
author="Author1, Author2",
author_email="email@email.com",
description="words words words.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/samplesample/sample1",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
],
entry_points='''
[console_scripts]
checklist=checklist.checklist:cli
''',
python_requires='>=3.7',
package_data={"checklist":["user_settings/*.pkl"]},
include_package_data=True,
)
if update:
for key in files:
pickle.dump(files[key], open(os.path.join(dir, key), "wb"))
当我尝试使用命令创建检查表
包时
python setup.py sdist bdist_wheel
我明白了
Error: Got unexpected extra arguments (sdist bdist_wheel)
当我从我的环境中删除单击
时,创建控制盘时不会出现问题。这似乎很奇怪,因为我的代码使用了单击
import os
import sys
import csv
import click
import datetime as dt
from datetime import datetime
from contextlib import suppress
import pickle
class UI:
def __init__(self):
<set variables>...
<some methods>...
# noinspection SpellCheckingInspection
class Checklist(UI):
def __init__(self):
<set variables>...
# start the process...
while self.step_index < len(self.to_do):
with suppress(ExitException):
self.step()
def step(self):
self.__getattribute__(self.to_do[self.step_index])()
self.step_index += 1
self.overwrite = False
<some methods>...
@click.command()
def cli():
Checklist()
cli()
导入操作系统
导入系统
导入csv
导入点击
将日期时间导入为dt
从日期时间导入日期时间
从上下文库导入抑制
进口泡菜
类用户界面:
定义初始化(自):
...
...
#无检查拼写检查检查
课堂检查表(UI):
定义初始化(自):
...
#开始这个过程。。。
当self.step\u index
这可能是什么原因造成的?我该如何解决这个问题?令人惊讶的是,与最佳实践的一些小偏差被联系在一起,产生了一个重大问题。:-)
单击的问题如下所示。如果安装了click
,则您的setup.py
将导入上面显示的模块。导入时,模块运行cli()
,saidcli()
调用@click.command()
,并解析命令行(用于setup.py
,而不是用于click
)并产生错误
如果未安装单击
,您的安装程序.py
尝试导入检查表
,但失败,出现模块查找错误
。在setup.py中捕获并忽略异常,然后继续安装
要解决此问题,请将检查表
制作成既可以运行(调用cli()
)又可以导入而无需调用cli()
)的模块:
令人惊讶的是,与最佳实践之间的一些小偏差被联系在一起,产生了一个重大问题。:-)
单击的问题如下所示。如果安装了click
,则您的setup.py
将导入上面显示的模块。导入时,模块运行cli()
,saidcli()
调用@click.command()
,并解析命令行(用于setup.py
,而不是用于click
)并产生错误
如果未安装单击
,您的安装程序.py
尝试导入检查表
,但失败,出现模块查找错误
。在setup.py中捕获并忽略异常,然后继续安装
要解决此问题,请将检查表
制作成既可以运行(调用cli()
)又可以导入而无需调用cli()
)的模块:
调用setuptools.setup(…)
之前是否有一些代码?我们能看看密码吗?代码中使用的模块是什么?很难在没有看到代码和完整回溯的情况下进行调试。@phd我添加了一些详细信息,但不想让这篇文章太过铺天盖地。除了错误消息之外,唯一的输出是建议尝试“setup.py--help”。在调用setuptools.setup(…)
之前是否有一些代码?我们能看看密码吗?代码中使用的模块是什么?很难在没有看到代码和完整回溯的情况下进行调试。@phd我添加了一些详细信息,但不想让这篇文章太过铺天盖地。除了错误消息之外,唯一的输出是建议尝试“setup.py--help”。
def main():
cli()
if __name__ == '__main__':
main()