python如何發布模塊


https://jingyan.baidu.com/article/59a015e375f55af794886591.html

一、准備發布

1、創建一個nester.py 模塊,創建nester 文件夾將nester.py模塊復制到這個文件夾

"# Author:guangqing"
''' 這是 "nester" 模塊,提供了一個名為print_lol()的函數,這個函數的作用是打印列表,其中有可能包含(也有可能不包含嵌套列表的類別)嵌套列表 '''
def print_lol(the_list):
    '''這個函數取一個位置參數,名為 'the_list'這可以是任何python列表(也可以是包含嵌套列表的列表)。所指定的列表中的每個數據項會(遞歸的)輸出到屏幕上,各個數據各占一行 '''
    for each_item in the_list:
        if isinstance(each_item,list):
            print_lol(each_item)
        else:
            print(each_item) 

2、在新文件夾中創建一個名為setup.py的文件;

from distutils.core import setup

setup(
    name='nester',
    version='1.0.0',
    py_modules =['nester'],
    author='jiale',
    author_email='18521093275@163.com',
    url='http://www.headfirstlabs.com',
    
    description='這是我的第一個發布安裝文件'
)

二、准備發布

1、接下來我們打開cmd窗口,進入到上面建立的文件夾下面,然后執行python setup.py sdist命令,如下圖所示(shift+右鍵,在此處打開powershell窗口)

PS D:\nester> python setup.py sdist
running sdist
running check
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)

warning: sdist: standard file not found: should have one of README, README.txt, README.rst

writing manifest file 'MANIFEST'
creating nester-1.0.0
making hard links in nester-1.0.0...
hard linking nester.py -> nester-1.0.0
hard linking setup.py -> nester-1.0.0
creating dist
Creating tar archive
removing 'nester-1.0.0' (and everything under it)
PS D:\nester>

2、將發布安裝到你的python本地副本中。

PS D:\nester> python setup.py install
running install
running build
running build_py
creating build
creating build\lib
copying nester.py -> build\lib
running install_lib
running install_egg_info
Removing D:\python\Lib\site-packages\nester-1.0.0-py3.7.egg-info
Writing D:\python\Lib\site-packages\nester-1.0.0-py3.7.egg-info
PS D:\nester>

 

1、在python 或IDLE shell中,鍵入dir(__builtins__)可以看到Python提供的內置方法列表;那些小寫的單詞都是BIF。要查看某個BIF做什么,比如說input(),可以在shell中鍵入help(input),就會得到這個BIF的功能描述;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM