当前位置: 移动技术网 > IT编程>脚本编程>Python > python的setup.py文件及其常用命令

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

2019年04月05日  | 移动技术网IT编程  | 我要评论

钩针编织教程,[雷神宫殿钥匙],太极张三丰背景音乐

编写setup.py文件,获取帮助:python setup.py --help-commands

[python] 
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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网