python打包和发布

setuptools工具

编写setupt.py文件

1
2
from setuptools import setup
setup(name="pyIP")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
python setup.py --help-commands
Standard commands:
build build everything needed to install
build_py "build" pure Python modules (copy to build directory)
build_ext build C/C++ extensions (compile/link to build directory)
build_clib build C/C++ libraries used by Python extensions
build_scripts "build" scripts (copy and fixup #! line)
clean clean up temporary files from 'build' command
install install everything from build directory
install_lib install all Python modules (extensions and pure Python)
install_headers install C/C++ header files
install_scripts install scripts (Python or otherwise)
install_data install data files
sdist create a source distribution (tarball, zip file, etc.)
register register the distribution with the Python package index
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
upload upload binary package to PyPI
check perform some checks on the package
Extra commands:
develop install package in 'development mode'
saveopts save supplied options to setup.cfg or other config file
egg_info create a distribution's .egg-info directory
upload_docs Upload documentation to PyPI
alias define a shortcut to invoke one or more commands
easy_install Find/get/install Python packages
rotate delete older distributions, keeping N newest files
bdist_egg create an "egg" distribution
install_egg_info Install an .egg-info directory for the package
test run unit tests after in-place build
setopt set an option in setup.cfg or another config file

sdist–创建一个发行树

1
python setup.py sdist

如果需要执行脚本

1
scripts=['bin/sshtool.py']

registerupload命令

pypi服务器,位于http://pypi.python.org/pypi.这是distutils包所使用的默认服务器.

1
2
3
python setup.py register
python setup.py sdist upload
python setup.py sdist upload -r pypi-server //可以选择服务器

会在主目录下存在一个.pypirc的文件保存帐号和密码.

坚持技术分享,您的支持将鼓励我继续创作!