简书Python

setup.py入门

2018-06-17  本文已影响27人  JinMoon

记录安装路径

增加 –record 参数重新安装软件包,执行命令:
python ./setup.py install --record install.txt

根据记录的安装路径删除

删除安装文件,执行命令:
cat install.txt | xargs rm -rf

开发者模式

python setup.py --help develop

Options for 'develop' command:
  --prefix                   installation prefix
  --zip-ok (-z)              install package as a zipfile
  --multi-version (-m)       make apps have to require() a version
  --upgrade (-U)             force upgrade (searches PyPI for latest versions)
  --install-dir (-d)         install package to DIR
  --script-dir (-s)          install scripts to DIR
  --exclude-scripts (-x)     Don't install scripts
  --always-copy (-a)         Copy all needed packages to install dir
  --index-url (-i)           base URL of Python Package Index
  --find-links (-f)          additional URL(s) to search for packages
  --build-directory (-b)     download/extract/build in DIR; keep the results
  --optimize (-O)            also compile with optimization: -O1 for "python -
                             O", -O2 for "python -OO", and -O0 to disable
                             [default: -O0]
  --record                   filename in which to record list of installed
                             files
  --always-unzip (-Z)        don't install as a zipfile, no matter what
  --site-dirs (-S)           list of directories where .pth files work
  --editable (-e)            Install specified packages in editable form
  --no-deps (-N)             don't install dependencies
  --allow-hosts (-H)         pattern(s) that hostnames must match
  --local-snapshots-ok (-l)  allow building eggs from local checkouts
  --version                  print version information and exit
  --no-find-links            Don't load find-links defined in packages being
                             installed
  --user                     install in user site-package
                             '/home/blastbao/.local/lib/python2.7/site-
                             packages'
  --uninstall (-u)           Uninstall this source package
  --egg-path                 Set the path to be used in the .egg-link file

使用命令:

[root@localhost section01]# python setup.py develop --record  install.txt
running develop
running egg_info
creating UNKNOWN.egg-info
writing UNKNOWN.egg-info/PKG-INFO
writing top-level names to UNKNOWN.egg-info/top_level.txt
writing dependency_links to UNKNOWN.egg-info/dependency_links.txt
writing manifest file 'UNKNOWN.egg-info/SOURCES.txt'
reading manifest file 'UNKNOWN.egg-info/SOURCES.txt'
writing manifest file 'UNKNOWN.egg-info/SOURCES.txt'
running build_ext
copying build/lib.linux-x86_64-2.7/lc_hello_world.so -> 
Creating /usr/lib64/python2.7/site-packages/UNKNOWN.egg-link (link to .)
Adding UNKNOWN 0.0.0 to easy-install.pth file

Installed /home/blastbao/workSpace/python/python-c-extension-sample/src/section01
Processing dependencies for UNKNOWN==0.0.0
Finished processing dependencies for UNKNOWN==0.0.0

正式安装

[blastbao@localhost section02]$ python setup.py install
running install
running bdist_egg
running egg_info
writing UNKNOWN.egg-info/PKG-INFO
writing top-level names to UNKNOWN.egg-info/top_level.txt
writing dependency_links to UNKNOWN.egg-info/dependency_links.txt
reading manifest file 'UNKNOWN.egg-info/SOURCES.txt'
writing manifest file 'UNKNOWN.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/lc_hello_world.so -> build/bdist.linux-x86_64/egg
creating stub loader for lc_hello_world.so
byte-compiling build/bdist.linux-x86_64/egg/lc_hello_world.py to lc_hello_world.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/UNKNOWN-0.0.0-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing UNKNOWN-0.0.0-py2.7-linux-x86_64.egg
Removing /usr/lib64/python2.7/site-packages/UNKNOWN-0.0.0-py2.7-linux-x86_64.egg
Copying UNKNOWN-0.0.0-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packages
UNKNOWN 0.0.0 is already the active version in easy-install.pth

Installed /usr/lib64/python2.7/site-packages/UNKNOWN-0.0.0-py2.7-linux-x86_64.egg

--record install.txt选项,使安装包信息记录到文件中,文件内容:

/usr/lib64/python2.7/site-packages/UNKNOWN-0.0.0-py2.7-linux-x86_64.egg

总结:

setup会
(1)编译c/c++文件成.so文件
(2)编译py文件成py文件
(3)生成元信息
(4)将上述文件打包成egg格式,然后拷贝到/usr/lib64/python2.7/site-packages/路径中
(5)相应安装包的信息记录在--record指定的文本文件中。

上一篇下一篇

猜你喜欢

热点阅读