- 浏览: 35728 次
最新评论
-
诗意的栖居:
我按照你给的地址下载了,安装了,但是mysql却不能启动:_m ...
MySQLdb for python 安装 -
诗意的栖居:
多谢,还是这样比较省事
MySQLdb for python 安装
Python中的setuptools工具不仅仅是简化了distutils 的setup.py文件的编写,更重要的是它的包管理能力方面的增强。它可以使用一种更加透明的方法来查找、下载并安装依赖包;并可以在一个包的多个版本中自由进行切换,这些版本都安装在同一个系统上;也可以声明对某个包的特定版本的需求;还可以只使用一个简单的命令就能更新到某个包的最新版本。说白了,这个和java中的Maven,以及在centos中使用的Yum有相似的地方;下面,先对以下几个名词作一个解释:
1.distutils
distutils
(1)Part of the Python standard library since version 1.6(自1.6版本,加入python标准库)
(2)The standard way of building and installing packages(构建、安装包的标准方法)
(3)Primary functionality in distutils.core
(4) Developer or packager creates setup.py
#!/usr/bin/env python
from distutils.core import setup
setup (name = “foo”,
version = “1.0”,
py_modules = [“foo”])
$ python setup.py sdist (create a source distribution)
$ python setup.py bdist (create a build distribution)
$ python setup.py install (install using defaults)
* Other --install-* options (remember to update $PYTHONPATH)
setup中的参数说明:
setup ( | arguments ) |
The setup function takes a large number of arguments. These are laid out in the following table.
name | The name of the package | a string |
version | The version number of the package | See distutils.version |
description | A single line describing the package | a string |
long_description | Longer description of the package | a string |
author | The name of the package author | a string |
author_email | The email address of the package author | a string |
maintainer | The name of the current maintainer, if different from the author | a string |
maintainer_email | The email address of the current maintainer, if different from the author | |
url | A URL for the package (homepage) | a URL |
download_url | A URL to download the package | a URL |
packages | A list of Python packages that distutils will manipulate | a list of strings |
py _modules | A list of Python modules that distutils will manipulate | a list of strings |
scripts | A list of standalone script files to be built and installed | a list of strings |
ext_modules | A list of Python extensions to be built | A list of instances of distutils.core.Extension |
classifiers | A list of categories for the package | The list of available categorizations is at http://cheeseshop.python.org/pypi?:action=list_classifiers . |
distclass | the Distribution class to use | A subclass of distutils.core.Distribution |
script_name | The name of the setup.py
script - defaults to sys.argv[0]
|
a string |
script_args | Arguments to supply to the setup script | a list of strings |
options | default options for the setup script | a string |
license | The license for the package | |
keywords | Descriptive meta-data. See PEP 314 | |
platforms | ||
cmdclass | A mapping of command names to Command subclasses | a dictionary |
2.setuptools
1) A collection of enhancements to the Python distutils package that allow one to more easily build and
distribute python packages(对distutils包的增强,使用setuptools可以更加方便的构建、发布python packages)
2)Additional set of keyword arguments to setup()(在distutils.core.setup的基础上,添加了一些新的参数)
3)Includes easy_install.py (包括一个easy_install.py工具,提供类似centos中的yum安装工具)
4) Creates eggs (.egg)(关于egg,最好的解释还是:‘Eggs are to Pythons as Jars are to Java…‘)
5)Features for developers (e.g. support for data files,MANIFEST, Pyrex, PyPI upload,…)
6)Ability to deploy project in “development mode” via setup.py develop command.
3. egg文件
Eggs
“Eggs are to Pythons as Jars are to Java…” ------------Phillip J. Eby
(1)Single-file importable distribution format .(这句话的意思是说,python中导入挂钩的更改,只要把egg加入到PYTHONPATH或者sys.path中,就可以像往常一样导入)
(2)Eggs are Zipfiles using the .egg extension, that support including data and C extensions as well as Python code
(egg也不一定是zipfile,setup的参数中有一个zip_safe参数,在程序打包时决定是否压缩,如果不指定,bdist_egg会对工程中的每一个文件作检查,具体的解释如下:)
(关于egg中是否会打包.py以外的数据、文件,在setup中有3个参数控制,具体如下:)
这里有一个例子:
The distutils have traditionally allowed installation of "data files", which are placed in a platform-specific location. However, the most common use case for data files distributed with a package is for use by the package, usually by including the data files in the package directory.
Setuptools offers three ways to specify data files to be included in your packages. First, you can simply use the include_package_data keyword, e.g.:
from setuptools import setup, find_packages setup( ... include_package_data = True )
This tells setuptools to install any data files it finds in your packages. The data files must be under CVS or Subversion control, or else they must be specified via the distutils' MANIFEST.in file. (They can also be tracked by another revision control system, using an appropriate plugin. See the section below on Adding Support for Other Revision Control Systems for information on how to write such plugins.)
If you want finer-grained control over what files are included (for example, if you have documentation files in your package directories and want to exclude them from installation), then you can also use the package_data keyword, e.g.:
from setuptools import setup, find_packages setup( ... package_data = { # If any package contains *.txt or *.rst files, include them: '': ['*.txt', '*.rst'], # And include any *.msg files found in the 'hello' package, too: 'hello': ['*.msg'], } )
The package_data argument is a dictionary that maps from package names to lists of glob patterns. The globs may include subdirectory names, if the data files are contained in a subdirectory of the package. For example, if the package tree looks like this:
setup.py src/ mypkg/ __init__.py mypkg.txt data/ somefile.dat otherdata.dat
The setuptools setup file might look like this:
from setuptools import setup, find_packages setup( ... packages = find_packages('src'), # include all packages under src package_dir = {'':'src'}, # tell distutils packages are under src package_data = { # If any package contains *.txt files, include them: '': ['*.txt'], # And include any *.dat files found in the 'data' subdirectory # of the 'mypkg' package, also: 'mypkg': ['data/*.dat'], } )
Notice that if you list patterns in package_data under the empty string, these patterns are used to find files in every package, even ones that also have their own patterns listed. Thus, in the above example, the mypkg.txt file gets included even though it's not listed in the patterns for mypkg .
Also notice that if you use paths, you must use a forward slash (/ ) as the path separator, even if you are on Windows. Setuptools automatically converts slashes to appropriate platform-specific separators at build time.
(Note: although the package_data argument was previously only available in setuptools , it was also added to the Python distutils package as of Python 2.4; there is some documentation for the feature available on the python.org website.)
Sometimes, the include_package_data or package_data options alone aren't sufficient to precisely define what files you want included. For example, you may want to include package README files in your revision control system and source distributions, but exclude them from being installed. So, setuptools offers an exclude_package_data option as well, that allows you to do things like this:
from setuptools import setup, find_packages setup( ... packages = find_packages('src'), # include all packages under src package_dir = {'':'src'}, # tell distutils packages are under src include_package_data = True, # include everything in source control # ...but exclude README.txt from all packages exclude_package_data = { '': ['README.txt'] }, )
The exclude_package_data option is a dictionary mapping package names to lists of wildcard patterns, just like the package_data option. And, just as with that option, a key of '' will apply the given pattern(s) to all packages. However, any files that match these patterns will be excluded from installation, even if they were listed in package_data or were included as a result of using include_package_data .
In summary, the three options allow you to:
NOTE: Due to the way the distutils build process works, a data file that you include in your project and then stop including may be "orphaned" in your project's build directories, requiring you to run setup.py clean --all to fully remove them. This may also be important for your users and contributors if they track intermediate revisions of your project using Subversion; be sure to let them know when you make changes that remove files from inclusion so they can run setup.py clean --all .
(3)Requires Python 2.3 or above
(4)Eggs are built using the setuptools package;eg:
python2.4 setup.py bdist_egg
(5)The published plan is to propose inclusion in the Python 2.5 standard library.(这个计划没有实现)
这个是我在http://www.ibm.com/developerworks/cn/linux/l-cppeak3.html
上节选过来的,说的很好:
egg
是一个包含所有包数据的文件包。在理想情况中,egg 是一个使用 zip 压缩的文件,其中包括了所有需要的包文件。但是在某些情况下,setuptools
会决定(或被开关告知)包不应该是 zip 压缩的。在这些情况下,egg 只是一个简单的未曾压缩的子目录,但是里面的内容是相同的。使用单一的版本可以方便地进行转换,并可以节省一点磁盘空间,但是 egg 目录从功能和组织结构上来说都是相同的。一直使用 JAR 文件的 Java™ 技术的用户会发现 egg 非常熟悉。
由于最新的 Python 版本中(需要 2.3.5+ 或 2.4)导入挂钩的更改,可以简单地通过设置 PYTHONPATH
或 sys.path
并像往常一样导入相应的包来使用 egg。如果希望采用这种方法,就不需要使用 setuptools
或 ez_setup.py
了。例如,在本文使用的工作目录中,我就为 PyYAML 包放入了一个 egg。现在我就可以使用这个包了,方法如下:
% export PYTHONPATH=~/work/dW/PyYAML-3.01-py2.4.egg % python -c 'import yaml; print yaml.dump({"foo":"bar",1:[2,3]})' 1: [2, 3] foo: bar |
(在这个地方,我想说一下,你必须使用过setuptools才会有eazy-install.pth)
不过,PYTHONPATH
的(或者脚本或 Python shell 会话内的 sys.path
的)这种操作有些脆弱。egg 的发现最好是在新一点的 .pth 文件中进行。在 site-packages/ 或 PYTHONPATH
中的任何 .pth 文件都会进行解析来执行其他导入操作,其方法类似于检查可能包含包的那些目录位置一样。如果使用 setuptools
来处理包的管理功能,那么在安装、更新、删除包时,就需要修改一个名为 easy-install.pth 的文件。而且可以按照自己喜欢的方式对这个 .pth 进行命名(只要其扩展名是 .pth 即可)。例如,下面是我的 easy-install.pth 文件的内容:
% cat /sw/lib/python2.4/site-packages/easy-install.pth
import sys; sys.__plen = len(sys.path)
setuptools-0.6b1-py2.4.egg
SQLObject-0.7.0-py2.4.egg
FormEncode-0.5.1-py2.4.egg
Gnosis_Utils-1.2.1-py2.4.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
p=getattr(sys,'__egginsert',0); sys.path[p:p]=new;
sys.__egginsert = p+len(new)
|
这种格式有点特殊:它近似于一个 Python 脚本,但却不完全是。需要说明的是,可以在那里添加额外列出的 egg;更好的情况是,easy_install
会在运行时实现这种功能。也可以在 site-packages/ 下创建任意多个 .pth 文件;每个都可以列出有哪些 egg 是可用的。
Why bother with Eggs?
1)Enable tools like “Easy Install” Python package manager(这个很显然)
2)They are a “zero installation” format for pure Python packages (put them on PYTHONPATH or sys.path)(上面说的那个.pth)
3)They can include package metadata (e.g. dependencies)
4)They allow namespace packages (packages that contain other packages) to be split into separate distributions
5)They allow applications or libraries to specify the needed version of a library before doing an import (e.g. require(“Twisted-Internet>=2.0”) )(这个涉及到的是setup里install_requires参数)
6)They provide a framework for plug-ins (similar to Eclipse’s extension point)
7)Enables one to distribute a project that depends on other software available via PyPI a.k.a. Cheese Shop.(eazy_install或者执行python setup.py install时,会依据install_requires参数自动从http://www.python.org/pypi/
上寻找规定的版本,并下载安装好这些依赖的包)
4. eazy_install
Easy Install / easy_install.py
1)A Python module bundled with setuptools that lets one automatically build, install, and manage python
packages
2)Part of the setuptools package
3)Installs any distutils-based package
4)Can find packages on PyPI
5)Handles dependencies via arguments to setup() (e.g. install_requires = [‘foo>=1.4’,’Bar’] )
[1]http://docs.python.org/distutils/index.html
[2]http://peak.telecommunity.com/DevCenter/setuptools
[3]http://peak.telecommunity.com/DevCenter/PythonEggs
[4]http://peak.telecommunity.com/DevCenter/EasyInstall
[5]http://www.ibm.com/developerworks/cn/linux/l-cppeak3.html
发表评论
-
python 的函数Decorators
2010-03-05 16:41 640Decorators是python中比较难以理解的东西,当然如 ... -
Python Unicode与中文处理
2010-03-19 15:06 890python中的unicode是让人很 ... -
Python中的正则表达式匹配中文问题
2010-03-23 15:53 968python中正则表达式匹配中文是没有问题的,但是其中有一个关 ... -
MySQLdb for Python使用指南/Python的数据库操作
2010-03-24 13:19 807转载自:http://hi.baidu.com ... -
python MySQLdb示例代码
2010-03-24 13:25 627# -*- coding: utf-8 -*- imp ... -
有道难题 之 有道搜索框 java实现
2010-06-02 16:51 789这个题目是5.29号第一场的第二题,先说句题外话,众多的参加的 ... -
CentOS5.4上将Python版本升级到2.6.5
2010-08-12 16:07 909CentOS5.4上将Python版本升级到2.6.5 ... -
MySQLdb for python 安装
2011-04-23 14:12 904升级到了python2.7.1,没 ... -
python lib 之 operator
2011-05-06 16:29 910operator module在使用内置函数如map,iter ... -
python mysql 分页程序
2011-10-09 16:00 3595#!/usr/bin/env python # -*- co ... -
How-To Guide for Descriptors
2011-10-20 11:07 860How-To Guide for Descriptors ... -
python __getattribute__ 的优先级问题
2011-10-26 14:54 1945The way __getattribute__ ... -
Thundering Herd Mitigation (memcached redis)
2012-04-25 16:38 1123"Modified memcached cache ... -
python 算法
2011-10-21 17:14 572http://code.activestate.com/rec ...
相关推荐
setuptools-40.0.0是一个用于python的构建工具集,压缩内打包了许多常用工具模块。方便我们安装python下的一些其他库,帮助你更为快捷的进行安装python相关库。资源列表:docspkg_resourcessetuptoolssetuptools.egg...
python包在开发中十分常见,一般的使用套路是所有的功能做一个python模块包,打包模块,然后发布,安装使用。这篇文章给大家介绍了python打包工具distutils、setuptools的相关知识,感兴趣的朋友一起看看吧
Python打包分发工具setuptools:曾经 Python 的分发工具是 distutils,但它无法定义包之间的依赖关系。setuptools 则是它的增强版,能帮助我们更好的创建和分发 Python 包,尤其是具有复杂依赖关系的包。其通过添加一...
CMake的Setuptools扩展:Cmake构建系统与setuptools的无缝集成该Python软件包提供了setuptools的扩展,以将CMake集成到setuptools工作流中。 CMake构建工具的任务是构建/安装带有二进制扩展名和必要数据文件的完整...
python 安装 打包PyInstaller安装失败 参照:https://blog.csdn.net/weixin_42312623/article/details/89930356 (1)pip install pywin32; (2)pip install wheel (3)pip install -U setuptools (4)pip ...
有关安装,升级和卸载Setuptools的说明,请参见《 Python打包用户指南》中的“安装说明”。 问题和评论应直接发送到distutils-sig邮件列表。 有关安装,升级和卸载Setuptools的说明,请参见《 Python打包用户指南》...
python自动转换成exe的工具, python版本是2.7 需要PySide,setuptools,pywin32,PyInstaller
该工具用于python的构建工具, 其中打包了许多常用工具模块
setuptools、distutils和wheel都是Python的打包工具,用于将Python代码打包成可安装的软件包,但它们有一些区别和用途上的差异。
有关安装,升级和卸载Setuptools的,请参见《 Python打包用户指南》中的“”。 问题和评论应直接发送到。 错误报告,尤其是经过测试的补丁程序,可以直接提交给。 行为守则 在setuptools项目的代码库,问题跟踪器,...
演示演示了使用Python和ctypes打包命令行工具的过程。 它从C代码创建共享库,并使用numpy.ctypes调用共享库。 pip install git+git://github.com/banskt/cpydemo.git或者,克隆存储库并从根目录安装pip install ....
久负盛名的 Python 入门经典针对 Python 3 全新升级十个出色的项目,让你尽快可以使用 Python 解决实际问题目录第 1章 快速上手:基础知识 ........................ 1 1.1 交互式解释器 .............................
需要安装easy-install模块,这是一个python的模块打包工具。 首先下载easy_setup.py的源代码,下载地址: http://pypi.python.org/pypi/setuptools 自己用记事本存放源代码用.py后缀名,在命令行执行即可,这样你...
tng-sdk-project 该存储库包含tng-sdk-project组件,该组件是欧洲H2020项目 NFV SDK的一...需要Python 3.5+和setuptools 。 为了简单,自动地安装和使用: # latest release from PyPi $ pip install tngsdk.projec
pip 是一个安装和管理 Python 包的工具,python安装包的工具有easy_install, setuptools, pip,distribute等。distribute是setuptools的替代品,是对标准库disutils模块的增强,我们知道disutils主要是用来更加容易...
sdsstools提供了一些用于日志记录,配置处理,版本分析,打包等的常用工具。其主要目的是合并最初在发现的一些实用程序,使它们成为可以更新的依赖项。 这并不是要成为天文工具的万能库。 sdsstools本身旨在具有...