如何将自定义的python文件上传至pipy官网

2021-03-31  本文已影响0人  CPinging

本文将指导用户如何将DIY的python包上传至Pypi官网,从而可以通过pip3 install进行下载。

一、文件准备

我们需要准备如下文件:

image.png

其中蓝色的为文件夹,白色的为普通文件。

MIT License
  
Copyright (c) 2021 The Python Packaging Authority

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

这里需要注意语法是否错误,否则会无法成功上传。

from setuptools import setup, Extension
import setuptools
with open("README.md", "r", encoding="utf-8") as fh:
    long_description = fh.read()

setup(
    name='xxxxxxxxx',
    version='0.0.1',
    author='xxxxx',
    author_email='xxxxxxxxxxxxx',
    url='',
    description=u'xxxxxxxxxxxxxxxxxxxxxxxx.',
    long_description_content_type="text/markdown",
    long_description = long_description,
    package_dir={"": "src"},
    packages=setuptools.find_packages(where="src"),
    install_requires=[],
    entry_points={
        'console_scripts': [
        ]
    }
)

在src目录中,创建文件夹(项目名称)

然后在这个项目文件夹中放入DIY的python代码:

image.png

然后创建init.py(from后的内容为python文件,import的为函数名)

from .DNN_printer import DNN_printer

二、指令

python3 setup.py sdist bdist_wheel首先运行指令来创建dist中的tar.gz文件

然后安装twine

调用twine check dist/*检查是否安装好

之后在pypi官网注册帐号

twine upload dist/*输入用户名密码进行上传

image.png

三、注意事项

当需要更新代码文件时,记得将setup里面的版本号码更新一下,否则会失败。

上一篇 下一篇

猜你喜欢

热点阅读