Hannah&Judy教程之《教你上傳自己寫的python第三方庫到PyPi》

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 = "[email protected]"

#項目網址
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章