mkdir dada_openapi_python cd dada_openapi_python
在裏面在建立一個 dada_openapi_client
的文件夾,這個文件夾的名稱我故意建立的和上層目錄不同,以避免誤會,這個文件夾其實就是包名稱了html
mkdir dada_openapi_client cd dada_openapi_client
根據各自的業務場景來,我下面列舉一個我編寫的
dada_clientpython
如今項目邏輯已經完成,那麼開始作 PyPI 的包了git
setup.py
文件在dada_openapi_python
文件夾中,建立配置文件setup.py
,並填寫配置,下面貼出個人配置github
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2020/1/6 15:41 # @Author : Weiqiang.long # @Site : # @File : setup.py # @Software: PyCharm # @Description: import setuptools with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() setuptools.setup( name = "dada_openapi_client", version = "1.0.3", author = "Weiqiang.long", description = "達達簽名數據封裝", long_description = long_description, long_description_content_type="text/markdown", url = "https://github.com/longweiqiang/dada_openapi_python", packages = setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ] )
上面配置中的每一個字段具體含義,可參照官網文檔的2.8項說明segmentfault
dada_openapi_python
文件夾運行此命令python setup.py sdist bdist_wheel
python -m twine upload dist/*
Uploading distributions to https://upload.pypi.org/legacy/ Uploading dada_openapi_client-1.0.3-py3-none-any.whl 100%|████████████████████████████████████████████████████ ███████████████| 7.88k/7.88k [00:00<00:00, 10.6kB/s] Uploading dada_openapi_client-1.0.3.tar.gz 100%|████████████████████████████████████████████████████ ███████████████| 6.23k/6.23k [00:01<00:00, 4.43kB/s]
錯誤的用戶驗證信息,你須要建立一個用戶驗證文件 ~/.pypirc
api
在本身的用戶目錄下新建一個空白文件命名爲.pypirc,內容以下:bash
[distutils]index-servers=pypi [pypi]repository = https://upload.pypi.org/legacy/ username = XXX password = XXX
你須要先註冊你的包才能夠開始上傳markdown
你的PyPI帳戶還沒完成郵箱驗證,你須要去註冊郵箱找到一封驗證郵件完成驗證後再重試失敗的步驟。url
你的setup.py文件中的classifier信息有誤,請按官網的正確分類書寫classifier.code
你還沒打包就開始了上傳命令
文件已經存在了,你每一次上次都應該更新版本號。
https://packaging.python.org/tutorials/packaging-projects/ https://segmentfault.com/a/1190000008663126 http://xiaoh.me/2015/12/11/python-egg/