PIP和命令行的问题

发布于 2025-01-29 11:28:20 字数 2344 浏览 3 评论 0原文

我正在尝试创建一个Python Pip软件包。这也很好。我可以成功上传和下载软件包,并在Python代码中使用它。我做不到的是通过命令行使用Python软件包。在另一个Stackoverflow帖子中,我找到了指向教程的链接。我试图遵循它。显然我犯了一个错误。你们能帮我吗? 通过pip安装软件包 在这里,您可以看到安装工作。不幸的是,整个脚本不适合图像。 pip找不到软件包。 不幸的是,我无法直接嵌入图像,因此我将它们嵌入为链接。

我创建了一个简单的Python软件包。它在这里仅表示一个示例。在这里,您可以看到文件夹的结构

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",
    ],
)

I am trying to create a Python pip package. This works also well. I can successfully upload and download the package and use it in the Python code. What I can't do is to use the Python package via the command line. In another StackOverflow post I found the link to a tutorial. I tried to follow it. Obviously I made a mistake. Can you guys help me please ?
Installation of the package via pip
here you can see that the installation worked. Unfortunately, not the whole script fit on the image.
Pip does not find the package.
Unfortunately, I can't embed the images directly, so I'll just embed them as links.

I have created a simple Python package. It represents here only an example. Here you can see the structure of the folder

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

Here are the basic files shown.

main.py

from . import hello_world

if __name__ == '__main__':
    hello_world()

and init.py

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

In the following you can see the "setup.py". I am of the opinion that I have followed the instructions. But obviously I made a mistake somewhere. Can you please help me to correct this mistake.

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",
    ],
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-黛色若梦 2025-02-05 11:28:20

在您的setup.py文件中,您有此行...

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

这是通过命令行调用包装的切入点。这种配置要求输入点为hello-world,我尝试过,并且运行良好。

但是,在您的图像中,您运行riffecx,该未配置为软件包的入口点。

如果您希望入口点为Riffecx。将行更改为:

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

希望这有所帮助。

In your setup.py file you have this line...

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

This is the entry point to calling you package via command line. This configuration is asking the entry point to be hello-world, which I tried and it runs fine.

In your image however you run riffecx which is not configured as an entrypoint to the package.

If you wanted the entrypoint to be riffecx. change the line to:

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

Hope this helped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文