欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python庫如何打包到PyPI

 更新時間:2023年11月29日 08:36:28   作者:tian_shl  
這篇文章主要介紹了Python庫如何打包到PyPI問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

Python庫打包到PyPI

打開pypi官網(wǎng), 并注冊賬號

https://pypi.python.org/

創(chuàng)建并編輯.pypirc (注: 家目錄下創(chuàng)建)

tianshl@tianshl ~ $ vim .pypirc

[pypirc]
index-servers =
    pypi
    pypitest

[pypi]
repository=https://pypi.python.org/pypi

[pypitest]
repository=https://testpypi.python.org/pypi

[server-login]
username:tianshl
password:******

前提

1. 要打包的代碼必須是一個包(package)

2. 代碼是開源的

包(package) 創(chuàng)建包

右鍵 / New / Python Package / 輸入包名 / OK

創(chuàng)建成功后,查看目錄結(jié)構(gòu)

tianshl@tianshl wechat $ tree
.
└── wxReply
    └── __init__.py

實際上就是文件夾中包含__init__.py文件 

編寫要打包的源代碼

tianshl@tianshl wechat $ tree
.
└── wxReply
    ├── __init__.py
    └── wxReply.py

1 directory, 2 files

創(chuàng)建README.rst和setup.py文件

  • README.rst為說明文檔
  • setup.py為安裝腳本 (核心)

此時wechat包的目錄結(jié)構(gòu)

tianshl@tianshl wechat $ tree
.
├── README.rst
├── setup.py
└── wxReply
    ├── __init__.py
    └── wxReply.py

1 directory, 4 files

編輯setup.py內(nèi)容

# -*- coding: utf-8 -*-

from setuptools import setup, find_packages
from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
    long_description = f.read()

__author__ = 'tianshl'
__date__ = '2017/01/26'


setup(
    name='wxReply',                                 # 名稱
    version='1.0.6',                                # 版本號
    description='wxReply',                          # 簡單描述
    long_description=long_description,              # 詳細(xì)描述
    classifiers=[
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
    ],
    keywords='wechat robot weixin wxReply',         # 關(guān)鍵字
    author='tianshl',                               # 作者
    author_email='xiyuan91@126.com',                # 郵箱
    url='https://my.oschina.net/tianshl/blog',      # 包含包的項目地址
    license='MIT',                                  # 授權(quán)方式
    packages=find_packages(),                       # 包列表
    install_requires=['requests', 'itchat'],
    include_package_data=True,
    zip_safe=True,
)


校驗 (python setup.py check)

tianshl@tianshl wxReply $ python3 setup.py check
running check

注: running check 表示沒問題, 其他情況對照提示修改即可 

打包 (python setup.py sdist)

tianshl@tianshl wechat $ python3 setup.py sdist
running sdist
running egg_info
creating wxReply.egg-info
writing wxReply.egg-info/PKG-INFO
writing dependency_links to wxReply.egg-info/dependency_links.txt
writing requirements to wxReply.egg-info/requires.txt
writing top-level names to wxReply.egg-info/top_level.txt
writing manifest file 'wxReply.egg-info/SOURCES.txt'
reading manifest file 'wxReply.egg-info/SOURCES.txt'
writing manifest file 'wxReply.egg-info/SOURCES.txt'
running check
creating wxReply-1.0.6
creating wxReply-1.0.6/wxReply
creating wxReply-1.0.6/wxReply.egg-info
copying files to wxReply-1.0.6...
copying README.rst -> wxReply-1.0.6
copying setup.py -> wxReply-1.0.6
copying wxReply/__init__.py -> wxReply-1.0.6/wxReply
copying wxReply/wxReply.py -> wxReply-1.0.6/wxReply
copying wxReply.egg-info/PKG-INFO -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/SOURCES.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/dependency_links.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/requires.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/top_level.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/zip-safe -> wxReply-1.0.6/wxReply.egg-info
Writing wxReply-1.0.6/setup.cfg
creating dist
Creating tar archive
removing 'wxReply-1.0.6' (and everything under it)

此時wechat包的目錄結(jié)構(gòu)

tianshl@tianshl wechat $ tree
.
├── README.rst
├── dist
│   └── wxReply-1.0.6.tar.gz
├── setup.py
├── wxReply
│   ├── __init__.py
│   └── wxReply.py
└── wxReply.egg-info
    ├── PKG-INFO
    ├── SOURCES.txt
    ├── dependency_links.txt
    ├── requires.txt
    ├── top_level.txt
    └── zip-safe

3 directories, 11 files

上傳

tianshl@tianshl wxReply $ python3 setup.py sdist register upload
running sdist
running egg_info
writing wxReply.egg-info/PKG-INFO
writing dependency_links to wxReply.egg-info/dependency_links.txt
writing requirements to wxReply.egg-info/requires.txt
writing top-level names to wxReply.egg-info/top_level.txt
reading manifest file 'wxReply.egg-info/SOURCES.txt'
writing manifest file 'wxReply.egg-info/SOURCES.txt'
running check
creating wxReply-1.0.6
creating wxReply-1.0.6/wxReply
creating wxReply-1.0.6/wxReply.egg-info
copying files to wxReply-1.0.6...
copying README.rst -> wxReply-1.0.6
copying setup.py -> wxReply-1.0.6
copying wxReply/__init__.py -> wxReply-1.0.6/wxReply
copying wxReply/wxReply.py -> wxReply-1.0.6/wxReply
copying wxReply.egg-info/PKG-INFO -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/SOURCES.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/dependency_links.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/requires.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/top_level.txt -> wxReply-1.0.6/wxReply.egg-info
copying wxReply.egg-info/zip-safe -> wxReply-1.0.6/wxReply.egg-info
Writing wxReply-1.0.6/setup.cfg
Creating tar archive
removing 'wxReply-1.0.6' (and everything under it)
running register
Registering wxReply to https://upload.pypi.org/legacy/
Server response (410): Project pre-registration is no longer required or supported, so continue directly to uploading files.
running upload
Submitting dist/wxReply-1.0.6.tar.gz to https://upload.pypi.org/legacy/
Server response (200): OK

測試

注意:

如果本地修改過pip的源, 執(zhí)行search 或 install 時, 請修改為官方源或臨時使用官方源(如: pip3 install wxReply -i https://pypi.python.org/simple), 否則有可能提示包不存在, 原因是官方的pip源尚未同步到其他的源, 等一段時間就可以了(具體多久沒研究過) 

測試是否上傳成功

tianshl@tianshl wechat $ pip3 search wxReply
wxReply (1.0.6)  - wxReply

測試能否安裝成功

tianshl@tianshl ~ $ pip3 install wxReply
Collecting wxReply
  Downloading wxReply-1.0.6.tar.gz
Requirement already satisfied: requests in /usr/local/lib/python3.6/site-packages (from wxReply)
Requirement already satisfied: itchat in /usr/local/lib/python3.6/site-packages (from wxReply)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/site-packages (from requests->wxReply)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/local/lib/python3.6/site-packages (from requests->wxReply)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/site-packages (from requests->wxReply)
Requirement already satisfied: idna<2.7,>=2.5 in /usr/local/lib/python3.6/site-packages (from requests->wxReply)
Requirement already satisfied: pyqrcode in /usr/local/lib/python3.6/site-packages (from itchat->wxReply)
Requirement already satisfied: pypng in /usr/local/lib/python3.6/site-packages (from itchat->wxReply)
Building wheels for collected packages: wxReply
  Running setup.py bdist_wheel for wxReply ... done
  Stored in directory: /Users/tianshl/Library/Caches/pip/wheels/49/26/9e/883fd73919e7c2cce794b0acc212216441ced601d6062e2941
Successfully built wxReply
Installing collected packages: wxReply
Successfully installed wxReply-1.0.6

測試能否正常引入

tianshl@tianshl ~ $ python3
Python 3.6.2 (default, Jul 17 2017, 16:44:45) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wxReply
>>> 

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python實現(xiàn)五子棋算法

    python實現(xiàn)五子棋算法

    這篇文章主要為大家詳細(xì)介紹了python實現(xiàn)五子棋算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Python學(xué)習(xí)之直方圖均衡化原理詳解

    Python學(xué)習(xí)之直方圖均衡化原理詳解

    直方圖均衡化是以累計分布函數(shù)為核心,將原始圖像灰度直方圖從比較集中的某個灰度區(qū)間,非線性地映射為在全部灰度范圍內(nèi)的較均勻分布,從而增強對比度。本文將為大家詳細(xì)講解直方圖均衡化的原理,需要的可以參考一下
    2022-03-03
  • 利用Python實現(xiàn)斐波那契數(shù)列的方法實例

    利用Python實現(xiàn)斐波那契數(shù)列的方法實例

    這篇文章主要給大家介紹了關(guān)于如何利用Python實現(xiàn)斐波那契數(shù)列的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用Python具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • python解釋器pycharm安裝及環(huán)境變量配置教程圖文詳解

    python解釋器pycharm安裝及環(huán)境變量配置教程圖文詳解

    這篇文章主要介紹了python解釋器pycharm安裝及環(huán)境變量配置教程圖文詳解,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-02-02
  • 帶你徹底搞懂python操作mysql數(shù)據(jù)庫(cursor游標(biāo)講解)

    帶你徹底搞懂python操作mysql數(shù)據(jù)庫(cursor游標(biāo)講解)

    這篇文章主要介紹了帶你徹底搞懂python操作mysql數(shù)據(jù)庫(cursor游標(biāo)講解),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • 簡單文件操作python 修改文件指定行的方法

    簡單文件操作python 修改文件指定行的方法

    使用python進行簡略的文件讀寫
    2013-05-05
  • python入門語句基礎(chǔ)之if語句、while語句

    python入門語句基礎(chǔ)之if語句、while語句

    本文介紹了python入門語句基礎(chǔ)之if語句、while語句,if?語句讓你能夠檢查程序的當(dāng)前狀態(tài),并據(jù)此采取相應(yīng)的措施,而for?循環(huán)用于針對集合中的每個元素都一個代碼塊,而?while?循環(huán)不斷地運行,直到指定的條件不滿足為止,本文通過示例代碼詳解介紹,需要的朋友參考下吧
    2022-04-04
  • Python使用crontab模塊設(shè)置和清除定時任務(wù)操作詳解

    Python使用crontab模塊設(shè)置和清除定時任務(wù)操作詳解

    這篇文章主要介紹了Python使用crontab模塊設(shè)置和清除定時任務(wù)操作,結(jié)合實例形式分析了centos7平臺上Python安裝、python-crontab模塊安裝,以及基于python-crontab模塊的定時任務(wù)相關(guān)操作技巧,需要的朋友可以參考下
    2019-04-04
  • 安裝python時MySQLdb報錯的問題描述及解決方法

    安裝python時MySQLdb報錯的問題描述及解決方法

    這篇文章主要介紹了安裝python時MySQLdb報錯的問題描述及解決方法,需要的朋友可以參考下
    2018-03-03
  • python通過微信發(fā)送郵件實現(xiàn)電腦關(guān)機

    python通過微信發(fā)送郵件實現(xiàn)電腦關(guān)機

    這篇文章主要為大家詳細(xì)介紹了python通過微信發(fā)送郵件實現(xiàn)電腦關(guān)機,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06

最新評論