我正在try 创建一个Python pip包.这也很有效.我可以成功地上传和下载这个包,并在Python代码中使用它.我不能通过命令行使用Python包.在另一篇StackOverflow帖子中,我找到了一个教程的链接.我试着跟着它走.显然我犯了个错误.你们能帮帮我吗?

我创建了一个简单的Python包.这里只代表了一个例子.在这里你可以看到文件夹的 struct

Riffecs
|   .gitignore
|   .pylintrc
|   LICENSE
|   README.md
|   requirements.txt
|   setup.py
|
|
\---riffecs
        __init__.py
        __main__.py

以下是显示的基本文件.

main.py

from . import hello_world

if __name__ == '__main__':
    hello_world()

还有init.py

def hello_world():
    print("Hello world")

在以下内容中,您可以看到"setup.py".我认为我已遵照指示行事.但很明显我在某个地方犯了个错误.你能帮我纠正这个错误吗.

import io
import os
import setuptools


def read_description():
    url = "README.md"
    """ Read and Return the description """
    return io.open(os.path.join(os.path.dirname(__file__), url), encoding="utf-8").read()


def def_requirements():
    """ Check PIP Requirements """
    with open('requirements.txt', encoding='utf-8') as file_content:
        pip_lines = file_content.read().splitlines()
    return pip_lines


setuptools.setup(
    name="riffecs",
    version='0.0.3',
    description='test',
    entry_points={'console_scripts': ['hello-world=riffecs:hello_world',]},
    long_description=read_description(),
    long_description_content_type="text/markdown",
    license="MIT",
    keywords="test - riffecs",
    url="https://github.com/Riffecs/riffecs",
    packages=["riffecs"],
    install_requires=def_requirements(),
    python_requires=">=3.6",
    classifiers=[
        "Development Status :: 4 - Beta",
        "Intended Audience :: Developers",
        "Intended Audience :: Science/Research",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Programming Language :: Python :: 3.9",
        "Programming Language :: Python :: 3.10",
    ],
)

推荐答案

在你的setup.py文件中有一行...

entry_points={'console_scripts': ['hello-world=riffecs:hello_world',]},

这是通过命令行调用包的入口点.这个配置要求入口点为hello-world,我试过了,运行良好.

然而,在您的映像中,您运行的是未配置为包入口点的riffecx.

如果你希望入口点是riffecx.将行更改为:

entry_points={'console_scripts': ['riffecx=riffecs:hello_world']},

希望这有帮助.

Python相关问答推荐

从webhook中的短代码(而不是电话号码)接收Twilio消息

由于NEP 50,向uint 8添加-256的代码是否会在numpy 2中失败?

当使用keras.utils.Image_dataset_from_directory仅加载测试数据集时,结果不同

按列分区,按另一列排序

对所有子图应用相同的轴格式

Stacked bar chart from billrame

在Python中,从给定范围内的数组中提取索引组列表的更有效方法

python panda ExcelWriter切换动态公式到数组公式

下三角形掩码与seaborn clustermap bug

导入错误:无法导入名称';操作';

交替字符串位置的正则表达式

并行编程:同步进程

Python—在嵌套列表中添加相同索引的元素,然后计算平均值

删除特定列后的所有列

我可以不带视频系统的pygame,只用于游戏手柄输入吗?''

以极轴表示的行数表达式?

如何在Polars中将列表中的新列添加到现有的数据帧中?

如何在Python中画一个只能在对角线内裁剪的圆?

Sknowled线性回归()不需要迭代和学习率作为参数

PyTorch变压器编码器中的填充掩码问题