distutils
一、setuptools
1膘魄、安裝
Python 2.x: sudo apt-get install python-setuptools
Python 3.x: sudo apt-get install python3-setuptools
pip install --upgrade setuptools
2序攘、MANIFEST.in
文件打包配置模板文件甘改,配置格式:
include part1 part2 #包含匹配到的文件
exclude part1 part2 #排除匹配到的文件
recursive-include dir part1 part2 #i包含指定目錄及遞歸子目錄下匹配到的文件
recursive-exclude dir part1 part2 #排除指定目錄及遞歸子目錄下匹配到的文件
global-include part1 part2 #i包含源碼樹中所有匹配到的文件
global-exclude part1 part2 #i排除源碼樹中所有匹配到的文件
prune dir #排除指定目錄下所有文件,包括子目錄
graft dir #包含指定目錄下所有文件户矢,包括子目錄
其中:
- 涉及的路徑為目錄名获茬,而不是包名
- 多條配置順序不同侣灶,結(jié)果不同识脆,比如:
test1.rst沒有被包含
include test1.rst
global-exclude *.rst
test1.rst被包含
global-exclude *.rst
include test1.rst
另外打源碼包時设联,data files也會根據(jù)package_name.egg-info/SOURCES.txt文件拉取加匈,所以MANIFEST.in修改后,打包之前仑荐,要刪除該文件
package_data: 字典,包和文件匹配模板列表映射纵东,這里是包而非目錄
exclude_package_data:字典粘招,包和文件匹配模板列表映射,這里是包而非目錄
3偎球、setup.cfg
4洒扎、pbr
二、python包格式
1衰絮、源碼發(fā)布包
python setup.py sdist --formats=formats #支持打包成多種格式袍冷,formats:zip,gztar
支持的壓縮格式如下,默認(rèn)gztar
--formats=bztar bzip2'ed tar-file
--formats=gztar gzip'ed tar-file
--formats=tar uncompressed tar file
--formats=zip ZIP file
--formats=ztar compressed tar file
2猫牡、預(yù)構(gòu)建發(fā)布包
python setup.py bdist --formats=formats
python setup.py sdist --formats=formats #支持打包成多種格式胡诗,formats:egg,gztar
支持的壓縮格式如下,默認(rèn)gztar
--formats=rpm RPM distribution
--formats=gztar gzip'ed tar file
--formats=bztar bzip2'ed tar file
--formats=ztar compressed tar file
--formats=tar tar file
--formats=wininst Windows executable installer
--formats=zip ZIP file
--formats=msi Microsoft Installer
--formats=egg Python .egg file
此外還提供簡化的命令
bdist create a built (binary) distribution
bdist_dumb create a "dumb" built distribution
bdist_rpm create an RPM distribution
bdist_wininst create an executable installer for MS Windows
bdist_egg create an "egg" distribution
bdist_wheel create a wheel distribution
二淌友、pip
1煌恢、安裝
- 源碼安裝
源碼包地址:
https://pypi.python.org/pypi/pip
解壓進(jìn)入源碼目錄,執(zhí)行命令:
python setup.py install - 包管理器安裝
yum install -y python-pip - 安裝腳本
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # 下載安裝腳本
python2:python get-pip.py # 運(yùn)行安裝腳本
python3: python3 get-pip.py