HannahJudy教程之《教你上传自己写的python第三方库到PyPi》

Quinta ·
更新时间:2024-11-01
· 545 次阅读

1.第一步准备工作: 新建一个任意命名的文件夹’han’,用来存放库文件夹’PDESolverByDeepLearning’、权限文件’LICENSE’、上传库时需要用的’setup.py’文件和’README.txt’文件。如下图:
在这里插入图片描述
其中,'LICENSE’文件内容为:

MIT License Copyright (c) 2018 lichanghong 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.

‘setup.py’文件内容为:

# -*- coding:utf-8 -*- try: from setuptools import setup, find_packages except: from distutils.core import setup from codecs import open from os import path #版本号 VERSION = '2.1.2' #发布作者 AUTHOR = "Zuliang Han" #邮箱 AUTHOR_EMAIL = "1461790569@qq.com" #项目网址 URL = "https://github.com/Hanzuliang/PDESolverByDeepLearning" #项目名称 NAME = "PDESolverByDeepLearning" #项目简介 DESCRIPTION = "This package is suitable for solving the problem of one-dimensional n-order differential equation with Dirichlet boundary conditions." #LONG_DESCRIPTION为项目详细介绍,这里取README.md作为介绍 here = path.abspath(path.dirname(__file__)) with open(path.join(here, 'README.txt'), encoding='ISO-8859-1') as f: LONG_DESCRIPTION = f.read() #搜索关键词 KEYWORDS = ["Deep Learning", "Machine Learning", "Neural Networks", "Scientific computing", "Differential equations", "PDE solver"] #发布LICENSE LICENSE = "MIT" #包 PACKAGES = ["PDESolverByDeepLearning"] #具体的设置 setup( name=NAME, version=VERSION, description=DESCRIPTION, long_description=LONG_DESCRIPTION, classifiers=[ 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Intended Audience :: Developers', 'Operating System :: OS Independent', ], #指定控制台命令 entry_points={ 'console_scripts': [ 'PDESolver = PDESolverByDeepLearning:PDESolver', ], }, keywords=KEYWORDS, author=AUTHOR, author_email=AUTHOR_EMAIL, url=URL, license=LICENSE, packages=PACKAGES, install_requires=['matplotlib', 'numpy', 'tensorflow'], #依赖的第三方包 include_package_data=True, zip_safe=True, )

‘README.txt’文件中省略参数。
最后,库文件夹 ‘PDESolverByDeepLearning’内含库代码文件 ‘hanzuliang.py’和空的初始化文件’init.py’,如下图:
在这里插入图片描述
2.第二步:去 https://pypi.org/ 官网注册一个账号,记住你的用户名和密码,如下图:
在这里插入图片描述
3.最后一步:打开你的CMD。
(1)首先cd路径到最开始的那个任意命名的文件夹’han’中,我的电脑上运行的是cd Destkop\han,如下图:
在这里插入图片描述
(2)输入python setup.py check,来检查你的’setup.py’文件的配置内容是否有错误,如果有错误,根据提示修改即可,如下图:
在这里插入图片描述
(3)输入’python setup.py sdist’,对我们要上传的库文件进行压缩。
在这里插入图片描述
此时,我们的库文件夹变为下图的形式:
在这里插入图片描述
这一步即将所有文件都打包成了压缩包’PDESolverByDeepLearning-2.1.2.tar’,放在了文件夹’dist’中,请看下图:
在这里插入图片描述
在这里插入图片描述
(4)先通过输入pip install twine安装上传工具twine,然后输入twine upload dist/*进行上传,如下图:
在这里插入图片描述
然后,根据提示输入你刚才申请的PyPi用户名和密码,即开始上传。
4.最后通过pip install 你的库名称就可以安装好你的库,快乐的玩耍了!
2020/4/24/20:35
Hannah&Judy


作者:鲁能是冠军



pypi 程之 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号