• python的setup.py文件及其常用命令


    编写setup.py文件,获取帮助: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:
      rotate            delete older distributions, keeping N newest files
      develop           install package in 'development mode'
      setopt            set an option in setup.cfg or another config file
      saveopts          save supplied options to setup.cfg or other config file
      egg_info          create a distribution's .egg-info directory
      install_egg_info  Install an .egg-info directory for the package
      alias             define a shortcut to invoke one or more commands
      easy_install      Find/get/install Python packages
      bdist_egg         create an "egg" distribution
      test              run unit tests after in-place build
    


     

    standard commands(标准命令)是distutils内建命令,而Extra commands(附加命令)是像

    setuptools这样的第三方包创建的。

    命令详解:
    1.sdist:用来创建一个源码包,在windows下为zip格式,linux下为tag.gz格式 。
    setup.py示例:
    from setuptools import setup
    setup(name='xxx',version='0.1.1')
    打包命令:python setup.py sdist
    distutils将浏览包的路径,查找包含在档案中的文件,包括:
       1)所有py_modules、packages和scripts选项隐含的python源文件
       2)所有在ext_modules选项中列出的C源文件
       3)符合test/test*.py模式的文件
       4)README、README.txt、setup.py和setup.cfg文件


    如果需要包含更多文件,那么可以使用MANIFEST.in文件模版,示例如下:
    include xx.txt
    include yy/xx.txt
    ....
    2.bdist_egg:用来创建一个二进制分发版本,经常用来替代基于bdist生成的模式


    3.install:安装包到python中。另外,他还可能会安装在setup.py中的install_requires定义的

    相关模块,例如:

       install_requires=['...','...']

    删除一个包:1)删除这个包所创建的文件,2)删除在site-packages文件夹easy-install.pth文

    件中列举的所有引用。


    4.develop:编译并且在适当的位置安装包,然后添加一个简单的链接到python site-packages文

    件夹中,可以使用显式的-u选项删除包,例如:
     python setup.py develop
     python setup.py develop -u
        使用该方式比其他方式安装包更好一些

    5.创建一个新命令:这是由setuptools引入的,是一种将包定义为插件的简单方法,示例:
    ...entry_points='''
                    [distutils.commands]
      my_command=my.command.module.Class
                    '''
     

    6.打包时将其他类型的文件一起打包

       distutils默认是不会打包py文件以外的文件的,解决办法为在setup.py中加入:

    setup(
      name = 'srcDetect',
      version = '0.1.0',
      packages=find_packages(), 
      #include_package_data = True,
      package_data = {'':['*.txt']},  #这里将打包所有的txt文件
      license = 'GPL',
      keywords = 'test api mydemo',
      platforms = "Independant",
      url = '',
      
      data_files=[('d:\\a',['srcDetect/a.txt'])],   #安装包的时候执行,会将a.txt拷贝到d盘下的a文件夹中
        )


     

  • 相关阅读:
    20145107《Java程序设计》第一周学习计划
    Java 问卷调查
    2020-2021-1 20209303 《Linux内核原理与分析》第九周作业
    2020-2021-1 20209303 《linux内核原理与分析》第八周作业
    2020-2021-1 20209303 《linux内核原理与分析》第七周作业
    2020-2021-1 20209303《Linux内核原理与分析》第六周作业
    2020-2021-1 20209303《Linux内核原理与分析》第五周作业
    2020-2021-1 20209303《Linux内核原理与分析》第四周作业
    2020-2021-1 20209303《Linux内核原理与分析》第三周作业
    2020-2021-1 20209303《Linux内核原理与分析》第二周作业
  • 原文地址:https://www.cnblogs.com/chenjianhong/p/4144962.html
Copyright © 2020-2023  润新知