编写python的第三方库,最终要的一个工作就是编写setup.py了,其实如果我们下载过一些第三库的源代码文件,打开之后一般就会有一个setup.py,执行python setup.py install 就可以安装这个库了
from distutils.core import setup
#This is a list of files to install, and where
#(relative to the 'root' dir, where setup.py is)
#You could be more specific.
files = ["things/*"]
setup(name = "appname",
version = "100",
description = "yadda yadda",
author = "myself and I",
author_email = "[email protected]",
url = "whatever",
#Name the folder where your packages live:
#(If you have other packages (dirs) or modules (py files) then
#put them into the package directory - they will be found
#recursively.)
packages = ['package'],
#'package' package must contain files (see list above)
#I called the package 'package' thus cleverly confusing the whole issue...
#This dict maps the package name =to=> directories
#It says, package *needs* these files.
package_data = {'package' : files },
#'runner' is in the root.
scripts = ["runner"],
long_description = """Really long text here."""
#
#This next part it for the Cheese Shop, look a little down the page.
#classifiers = []
)
写完之后运行下面的命令
python setup.py sdist
在当前目录下,会创建dist目录,里面有个文件名为foo-1.0.tar.gz,这个就是可以分发的包。使用者拿到这个包后,解压,到foo-1.0目录下执行:python setup.py install。
buildout的是一款自动化构建工具。
由Zope团队开发维护。包名为zc.buildout。
buildout可以为应用构建独立的依赖环境。类似于virtualenv/miniconda,但二者还有不同。
粗略地讲,buildout支持的功能更多更便于自动化而且具体定位有所不同。
easy_install 和 pip的介绍:
easy_install和pip都是用来下载安装Python一个公共资源库PyPI
的相关资源包的,pip是easy_install的改进版,提供更好的提示信
息,删除package等功能。老版本的python某些python模块中只有easy_install的安装方式。
经常接触Python的同学可能会注意到,当需要安装第三方python包时,可能会用到easy_install命令。easy_install是由PEAK(Python Enterprise Application Kit)开发的setuptools包里带的一个命令,它用来安装egg包。egg包是目前最流行的python应用打包部署方式。
https://segmentfault.com/a/1190000007031057
freeze和部署
pip freeze >requirements.txt
pip install -r C:\Users\Administrator\requirements.txt