Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1104255
  • 博文数量: 170
  • 博客积分: 1603
  • 博客等级: 上尉
  • 技术积分: 1897
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-09 15:54
文章分类

全部博文(170)

文章存档

2016年(27)

2015年(21)

2014年(27)

2013年(21)

2012年(7)

2011年(67)

我的朋友

分类: LINUX

2015-01-09 15:35:54

python-setuptools/easy_install就TM一大坑

非常不方便管理,安装了也不容易卸载,我的原则是redhat系安装任何东西最好都遵循redhat的包管理那一套,
全部用rpm包来安装,如何打包python的模块呢?
弱智点点方法就直接指定文件位置,然后直接打包即可,不过观察下python可以用easy_install的模块的rpm包的desc文件就可以知道
easy_install的脚本还是很容易打包成rpm的

上一个示例的spec文件

点击(此处)折叠或打开

  1. %{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
  2. %define tarballversion 1.2.4
  3. Name: python-GeoIP
  4. Version: 1.2.5
  5. Release: %{?dist}
  6. Summary: Python bindings for the GeoIP geographical lookup libraries
  7. Group: Development/Languages
  8. License: LGPLv2+
  9. URL:
  10. Source0: GeoIP-Python-%{tarballversion}.tar.gz
  11. Patch0: python-GeoIP-1.2.4-ipv6.patch
  12. BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
  13. # GeoIP 1.4.7 needed for IPv6 lookup functions
  14. BuildRequires: python-devel, GeoIP-devel >= 1.4.7
  15. %description
  16. This package contains the Python bindings for the GeoIP API, allowing IP to
  17. location lookups to country, city and organization level within Python code.
  18. %prep
  19. %setup -q -n GeoIP-Python-%{tarballversion}
  20. %patch0 -p1
  21. %build
  22. CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
  23. # To avoid adding un-needed dependencies
  24. chmod -x test*.py
  25. %install
  26. rm -rf %{buildroot}
  27. %{__python} setup.py install -O1 --skip-build --root %{buildroot}
  28. %clean
  29. rm -rf %{buildroot}
  30. %files
  31. %defattr(-,root,root,-)
  32. %doc LICENSE README ChangeLog test*.py
  33. %{python_sitearch}/GeoIP.so
  34. %{python_sitearch}/GeoIP_Python*
  35. %changelog
  36. * Tue Sep 1 2009 Matt Domsch - 1.2.5-0.2.20090931cvs
  37. - fix prerelease versioning

install部分非常简单,所以,只要基于easy_install的模块,我们都按照这个模式写spec文件即可
当然,在打包服务器上python-setuptools/easy_install还是要安装的,因为打包过程中会用到
一不做二不休,我们先删除掉已经安装的非rpm包的setuptools
easy_install -m setuptools
根据上面命令的回显删除残留egg

python-setuptools/easy_install的最新版打个包

setuptools最新版本是11.1
下载下来后,用setuptools-0.6的spec文件改动下直接bulid就好

点击(此处)折叠或打开

  1. %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
  2. Name: python-setuptools
  3. Version: 11.1
  4. Release: 0%{?dist}
  5. Summary: Download, build, install, upgrade, and uninstall Python packages
  6. Group: Development/Languages
  7. License: Python or ZPLv2.0
  8. URL:
  9. #URL:
  10. #Source0: %{version}.tar.gz
  11. Source0: setuptools-%{version}.tar.gz
  12. BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
  13. BuildArch: noarch
  14. BuildRequires: python-devel
  15. Requires: python-devel
  16. Provides: python-setuptools-devel
  17. %description
  18. setuptools is a collection of enhancements to the Python distutils that allow
  19. you to more easily build and distribute Python packages, especially ones that
  20. have dependencies on other packages.
  21. %prep
  22. %setup -q -n setuptools-%{version}
  23. chmod -x *.txt
  24. find -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python}|'
  25. %build
  26. CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
  27. %install
  28. rm -rf $RPM_BUILD_ROOT
  29. %{__python} setup.py install -O1 --skip-build \
  30. --root $RPM_BUILD_ROOT \
  31. --single-version-externally-managed
  32. #install -p -m 0644 %{SOURCE1} %{SOURCE2} .
  33. find $RPM_BUILD_ROOT%{python_sitelib} -name '*.exe' | xargs rm -f
  34. find $RPM_BUILD_ROOT%{python_sitelib} -name '*.txt' | xargs chmod -x
  35. chmod +x $RPM_BUILD_ROOT%{python_sitelib}/setuptools/command/easy_install.py
  36. %clean
  37. rm -rf $RPM_BUILD_ROOT
  38. %files
  39. %defattr(-,root,root,-)
  40. %doc *.txt
  41. %{_bindir}/*
  42. %{python_sitelib}/*
  43. %changelog
  44. * Mon Jan 5 2015 ll - 11.1-0
  45. - Update to feature release 11.1

打包完毕后安装

现在我们来打包一个模块,比如python-openpyxl
首先,我们不是去打包python-openpyxl,而是先要搞定python-openpyxl的依赖关系
这个好办,我们直接用easy_install来解决依赖关系
先在编译机器上用easy_install 来安装openpyxl
安装完后,我们发现不仅安装了openpyxl,还安装了jdcal,咱不关心jdcal是干什么的,只知道openpyxl需要jdcal,
jdcal没有什么需要(其实可能是有的,但是因为本机已经装了很多模块了已经包含在里面)
安装完后,我们卸载掉已经用easy_install安装的的模块
easy_install -m jdcal
easy_install -m openpyxl
更具上两个命令的现实内容,删除掉残留的egg文件


于是打包openpyxl前,我们先打包jdcal,
上spec文件

点击(此处)折叠或打开

  1. %{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
  2. Name: python-jdcal
  3. Version: 1.0
  4. Release: 0%{?dist}
  5. Summary: A Python library contains functions for converting between Julian dates and calendar dates
  6. License: MIT and Python-2.0
  7. Group: Development/Languages/Python
  8. Url:
  9. Source: %{version}.tar.gz
  10. BuildRequires: python-devel
  11. BuildRequires: python-setuptools
  12. # for embedded image support
  13. BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
  14. #BuildRoot: %{_tmppath}/%{name}-%{version}-build
  15. BuildArch: noarch
  16. %description
  17. Julian dates from proleptic Gregorian and Julian calendars
  18. This module contains functions for converting between Julian dates and calendar dates
  19. %prep
  20. %setup -q -n jdcal-%{version}
  21. %build
  22. #python setup.py build
  23. CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
  24. %install
  25. #python setup.py install --prefix=%{_prefix} --root=%{buildroot}
  26. %{__python} setup.py install -O1 --skip-build --root %{buildroot}
  27. #mv LICENCE LICENSE
  28. %clean
  29. rm -rf %{buildroot}
  30. %files
  31. %defattr(-,root,root,-)
  32. %doc PKG-INFO
  33. %{python_sitelib}/*
  34. %changelog
  35. * Mon Jan 5 2015 ll - 1.0-0
  36. - Update to feature release 1.0

打包好python-jdcal后我们再打包python-openpyxl

点击(此处)折叠或打开

  1. %{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
  2. Name: python-openpyxl
  3. Version: 2.1.4
  4. Release: 0%{?dist}
  5. Summary: A Python library to read/write Excel 2007 xlsx/xlsm files
  6. License: MIT and Python-2.0
  7. Group: Development/Languages/Python
  8. Url:
  9. Source: %{version}.tar.gz
  10. BuildRequires: python-devel
  11. BuildRequires: python-setuptools
  12. Requires: python-jdcal
  13. # for embedded image support
  14. BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
  15. #BuildRoot: %{_tmppath}/%{name}-%{version}-build
  16. BuildArch: noarch
  17. %description
  18. openpyxl is a pure python reader and writer of Excel OpenXML files.
  19. It is ported from the PHPExcel project
  20. %prep
  21. %setup -q -n openpyxl-%{version}
  22. %build
  23. #python setup.py build
  24. CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
  25. %install
  26. #python setup.py install --prefix=%{_prefix} --root=%{buildroot}
  27. %{__python} setup.py install -O1 --skip-build --root %{buildroot}
  28. #mv LICENCE LICENSE
  29. %clean
  30. rm -rf %{buildroot}
  31. %files
  32. %defattr(-,root,root,-)
  33. %{python_sitelib}/*
  34. %changelog
  35. * Mon Jan 5 2015 lll - 2.1.4-0
  36. - This spec edit from an suse spec file Update to feature release 2.1.4
  37. * Thu Jul 17 2014 toddrme2178@gmail.com
  38. - Add LICENSE to %%doc
  39. * Thu Dec 5 2013 p.drouand@gmail.com
  40. - Update to version 1.7.0
  41. + Read CHANGES file from package documentation
  42. * Thu Oct 24 2013 speilicke@suse.com
  43. - Require python-setuptools instead of distribute (upstreams merged)
  44. * Fri May 10 2013 toddrme2178@gmail.com
  45. - Initial version

这样两个python-openpyx
l的rpm包及依赖包就做好了
其他机器需要python-openpyxl的直接安装rpm包即可,不需要安装setuptools

更新下, Requires项目点setup.py里有,对应的文档里也有
阅读(3392) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~