点上传脚本或模块 [英] pip upload script or module

查看:66
本文介绍了点上传脚本或模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是另一个问题的重复,我很抱歉(这是我在这里的第一个问题:))

I am sorry in advance if this is a duplicate of another question (and this is my first question here :) )

我想知道我们是否可以将脚本上传到pip而非软件包. 我目前正在编写代码,并希望通过pip将其提供给社区,但是我不确定这是否可能...

I would like to know if we can upload scripts to pip rather than packages. I am currently writing a code and would like to make it available to the community through pip but I am not sure if this is possible...

当我说软件包时,我的意思是我们可以用另一个代码内部调用

When I say package I mean something that we can call inside another code with

import blabla

编写脚本,以便我们可以像其他任何程序一样从终端调用这些脚本.

And script something that we can call from the terminal like any other program.

推荐答案

您可以上传脚本,但是如果要通过pip install将其提供给社区,则必须打包它们.这意味着您还需要编写一个setup.py文件.

You can upload scripts, but you have to package them if you want to make it available to the community through a pip install. That means you'll need to write a setup.py file, too.

# my_script.py
def main():
    ...

if __name__ == '__main__':
    main()

在安装文件中:

# setup.py
from setuptools import setup

setup(
    ...
    entry_points={
        'console_scripts': ['my_script=my_script:main'],
    },
)

您还需要了解其他有关将脚本上传到Python软件包索引的信息.查阅包装指南,例如 PyPI快速而肮脏.

There is other stuff you'll need to learn about to upload your script to the Python package index. Check out a packaging guide, such as PyPI Quick and Dirty.

这篇关于点上传脚本或模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆