python 打包工具

python 打包工具

一、distutils (python 标准库)

  1. 安装
    # 下载了源码发布文件foo-1.0.tar.gz
    # cd foo-1.0
    # python setup.py install
    
  2. 创建执行文件 hello.py
    def hello_fun():
       print "hello word"
    
  3. 配置文件 setup.py
    from distutils.core import setup 
    setup(
    	name="hello_module",
    	version="1.0",
    	author="ljk",
    	author_email="[email protected]",
    	py_modules=['hello'],
    	)
    
  4. 执行打包命令
    python setup sdist
    
  5. 打包成功(当前目录下自动生成了一个文件夹dist,文件夹中有一个压缩包即为我们的目标文件,另有一个记录文件MANIFEST)
    python 打包工具_第1张图片
  6. 安装(hello_module-1.0.tar.gz 是生成的python模块)
    sudo tar zvxf hello_module-1.0.tar.gz
    cd hello_module-1.0
    python setup.py install
    
  7. 使用 (模块就是hello.py文件,引用hello.py文件中的hello_fun(

你可能感兴趣的:(python)