Pypi 發布自己的包
阿新 • • 發佈:2019-03-17
href 環境要求 pack packages rar txt 函數 分享圖片 enc
- 註冊Pypi
- 驗證註冊郵箱
- 用我的一個包(git-clone)舉例
- 供參考項目:
- https://github.com/dhgdhg/git-clone
- https://github.com/dhgdhg/scrapy-chrome
- 必須的文件及文件夾
setup.py
from setuptools import setup, find_packages setup( name='git-clone', # 包名 version='1.0.5', # 版本號 description=('Git clone by downloading zip and decompressing it'), # 簡介 long_description=open('README.rst').read(), # 讀取README.rst的內容, 在pypi裏包主頁顯示 author='twfb', # 作者名 author_email='[email protected]', # 作者郵箱 maintainer='twfb', # 維護者名 maintainer_email='[email protected]', # 維護者郵箱 license='BSD License', packages=find_packages(), platforms=["all"], include_package_data=True, url='https://github.com/dhgdhg/git-clone/', # 包主頁顯示的鏈接 classifiers=[ 'Development Status :: 4 - Beta', 'Operating System :: OS Independent', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python', 'Programming Language :: Python :: Implementation', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Topic :: Software Development :: Libraries' ], entry_points={ # 可在命令行中執行的命令及對應的腳本, 如果沒有該需求可以不用寫 'console_scripts': ['git-clone=git_clone.git_clone:execute'], }), # install_requires=['scrapy>=1.0.0', 'selenium>=3.9.0']) #我這裏沒用到, 這個是安裝你的包環境要求
README.rst
- 懶得寫, 我就直接放github的鏈接了
https://github.com/dhgdhg/git-clone/
- git_clone文件下的
git_clone.py
- 下面就是該是內容了
def git_clone(): # 你寫的包裏面的方法 pass def execute(): # 沒有命令行命令需求的不用寫該函數 ''' setup.py中指定的腳本文件 entry_points={ # 可在命令行中執行的命令及對應的腳本 'console_scripts': ['git-clone=git_clone.git_clone:execute'], }), 這裏再解釋下 git-clone: 就是你在命令行中調用的命令 execute: 執行的函數名 ''' import sys git_clone(sys.argv[1], sys.argv[2], sys.argv[3]) # sys.argv 命令中的參數
- git_clone文件下的
__init__.py
python from .git_clone import git_clone
- 可選的文件及文件夾
README.md
- 用markdonw書寫, 上傳到github時用於項目介紹
requirements/requirements.txt
- 環境要求 方便直接安裝需要的庫
- 供參考項目:
- 生成pip安裝文件
python setup.py sdist bdist_wheel --universal
- 你會發現多個文件夾dist
- dist中的文件你可以先用pip install 測試下能不能用
- 上傳到pypi
- 安裝twine
pip install twine
- 上傳文件
twine upload dist/*
- 會提示你輸入用戶名, 然後輸入密碼, 註意密碼不要復制粘貼, 要手輸, 別問我怎麽知道的
- 安裝twine
Pypi 發布自己的包