如何將自己的python庫打包成wheel文件并上傳到pypi
如下圖,比如sigma目錄是我要上傳的項(xiàng)目,在six-sigma目錄下新建三個文件,分別是LICENSE也就是開源協(xié)議,README.md文件,用于介紹自己的項(xiàng)目和setup.py這個配置文件,此文件配置關(guān)于項(xiàng)目和作者的一些信息,接下來我們一一介紹。

Copyright (c) 2018 The Python Packaging Authority
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the 'Software'), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.
README.md文件# Example PackageThis is a simple example package. You can use[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)to write your content.setup.py文件
import setuptoolswith open('README.md', 'r', encoding='utf-8') as fh: long_description = fh.read()setuptools.setup( name='sigma_t', # 項(xiàng)目名稱 version='0.0.1', # 項(xiàng)目版本信息 author='AlanRick', # 作者 寫你的真實(shí)姓名即可 author_email='zs13128488417@gmail.com', # 作者郵箱 description='six sigma project', # 項(xiàng)目簡介 long_description=long_description, # 項(xiàng)目詳細(xì)的介紹 這里直接讀取README.md文件 long_description_content_type='text/markdown', # 項(xiàng)目詳細(xì)介紹的文件類型 classifiers=['Programming Language :: Python :: 3','License :: OSI Approved :: MIT License','Operating System :: OS Independent', ], package_dir={'': 'src'}, # 自己的包所在目錄 packages=setuptools.find_packages(where='src'), # 所有模塊所在目錄 python_requires='>=3.6', # python所需要的版本)安裝所需插件
確保您已經(jīng)在pypi.org上注冊了賬號,然后執(zhí)行以下命令
pip install wheelpip install twine打包文件為*.whl
首先在終端cd到setup.py文件所在目錄下,并在終端執(zhí)行以下命令進(jìn)行打包
python setup.py bdist_wheel
打包完成生成如下文件

python -m twine upload dist/sigma-0.0.1-py3-none-any.whl
如下在終端提示您輸入用戶名和密碼然后進(jìn)行上傳

如下上傳成功

在pypi項(xiàng)目管理頁面可以看到剛上傳好的文件

點(diǎn)開項(xiàng)目可以看到我們的配置文件顯示在前端了


也可以參考pypi官網(wǎng)的方法進(jìn)行上傳。
到此這篇關(guān)于如何將自己的python庫打包成wheel文件并上傳到pypi的文章就介紹到這了,更多相關(guān)python庫打包成wheel并上傳到pypi內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 基于android studio的layout的xml文件的創(chuàng)建方式2. 解決Android studio xml界面無法預(yù)覽問題3. 詳解Android studio 動態(tài)fragment的用法4. 圖文詳解vue中proto文件的函數(shù)調(diào)用5. 什么是python的自省6. Spring Boot和Thymeleaf整合結(jié)合JPA實(shí)現(xiàn)分頁效果(實(shí)例代碼)7. Android如何加載Base64編碼格式圖片8. 使用Android studio查看Kotlin的字節(jié)碼教程9. Vuex localStorage的具體使用10. Vue封裝一個TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)

網(wǎng)公網(wǎng)安備