python-setuptools/easy_install就TM一大坑
非常不方便管理,安装了也不容易卸载,我的原则是redhat系安装任何东西最好都遵循redhat的包管理那一套,
全部用rpm包来安装,如何打包python的模块呢?
弱智点点方法就直接指定文件位置,然后直接打包即可,不过观察下python可以用
easy_install的模块的rpm包的desc文件就可以知道
easy_install的脚本还是很容易打包成rpm的
上一个示例的spec文件
-
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
-
%define tarballversion 1.2.4
-
Name: python-GeoIP
-
Version: 1.2.5
-
Release: %{?dist}
-
Summary: Python bindings for the GeoIP geographical lookup libraries
-
-
Group: Development/Languages
-
License: LGPLv2+
-
URL:
-
Source0: GeoIP-Python-%{tarballversion}.tar.gz
-
Patch0: python-GeoIP-1.2.4-ipv6.patch
-
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
-
# GeoIP 1.4.7 needed for IPv6 lookup functions
-
BuildRequires: python-devel, GeoIP-devel >= 1.4.7
-
-
%description
-
This package contains the Python bindings for the GeoIP API, allowing IP to
-
location lookups to country, city and organization level within Python code.
-
-
%prep
-
%setup -q -n GeoIP-Python-%{tarballversion}
-
%patch0 -p1
-
-
%build
-
CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
-
# To avoid adding un-needed dependencies
-
chmod -x test*.py
-
-
%install
-
rm -rf %{buildroot}
-
%{__python} setup.py install -O1 --skip-build --root %{buildroot}
-
-
-
%clean
-
rm -rf %{buildroot}
-
-
-
%files
-
%defattr(-,root,root,-)
-
%doc LICENSE README ChangeLog test*.py
-
%{python_sitearch}/GeoIP.so
-
%{python_sitearch}/GeoIP_Python*
-
-
-
%changelog
-
* Tue Sep 1 2009 Matt Domsch - 1.2.5-0.2.20090931cvs
-
- 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就好
-
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
-
-
Name: python-setuptools
-
Version: 11.1
-
Release: 0%{?dist}
-
Summary: Download, build, install, upgrade, and uninstall Python packages
-
-
Group: Development/Languages
-
License: Python or ZPLv2.0
-
URL:
-
#URL:
-
#Source0: %{version}.tar.gz
-
Source0: setuptools-%{version}.tar.gz
-
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
-
BuildArch: noarch
-
BuildRequires: python-devel
-
-
Requires: python-devel
-
-
Provides: python-setuptools-devel
-
-
%description
-
setuptools is a collection of enhancements to the Python distutils that allow
-
you to more easily build and distribute Python packages, especially ones that
-
have dependencies on other packages.
-
-
-
%prep
-
%setup -q -n setuptools-%{version}
-
chmod -x *.txt
-
find -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python}|'
-
-
-
%build
-
CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
-
-
-
%install
-
rm -rf $RPM_BUILD_ROOT
-
%{__python} setup.py install -O1 --skip-build \
-
--root $RPM_BUILD_ROOT \
-
--single-version-externally-managed
-
#install -p -m 0644 %{SOURCE1} %{SOURCE2} .
-
find $RPM_BUILD_ROOT%{python_sitelib} -name '*.exe' | xargs rm -f
-
find $RPM_BUILD_ROOT%{python_sitelib} -name '*.txt' | xargs chmod -x
-
chmod +x $RPM_BUILD_ROOT%{python_sitelib}/setuptools/command/easy_install.py
-
-
-
%clean
-
rm -rf $RPM_BUILD_ROOT
-
-
%files
-
%defattr(-,root,root,-)
-
%doc *.txt
-
%{_bindir}/*
-
%{python_sitelib}/*
-
-
-
%changelog
-
* Mon Jan 5 2015 ll - 11.1-0
-
- 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文件
-
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
-
-
Name: python-jdcal
-
Version: 1.0
-
Release: 0%{?dist}
-
Summary: A Python library contains functions for converting between Julian dates and calendar dates
-
License: MIT and Python-2.0
-
Group: Development/Languages/Python
-
Url:
-
Source: %{version}.tar.gz
-
BuildRequires: python-devel
-
BuildRequires: python-setuptools
-
# for embedded image support
-
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
#BuildRoot: %{_tmppath}/%{name}-%{version}-build
-
BuildArch: noarch
-
-
%description
-
Julian dates from proleptic Gregorian and Julian calendars
-
This module contains functions for converting between Julian dates and calendar dates
-
-
%prep
-
%setup -q -n jdcal-%{version}
-
-
%build
-
#python setup.py build
-
CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
-
-
%install
-
#python setup.py install --prefix=%{_prefix} --root=%{buildroot}
-
%{__python} setup.py install -O1 --skip-build --root %{buildroot}
-
#mv LICENCE LICENSE
-
-
%clean
-
rm -rf %{buildroot}
-
-
%files
-
%defattr(-,root,root,-)
-
%doc PKG-INFO
-
%{python_sitelib}/*
-
-
%changelog
-
* Mon Jan 5 2015 ll - 1.0-0
-
- Update to feature release 1.0
打包好python-jdcal后我们再打包python-openpyxl
-
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
-
-
Name: python-openpyxl
-
Version: 2.1.4
-
Release: 0%{?dist}
-
Summary: A Python library to read/write Excel 2007 xlsx/xlsm files
-
License: MIT and Python-2.0
-
Group: Development/Languages/Python
-
Url:
-
Source: %{version}.tar.gz
-
BuildRequires: python-devel
-
BuildRequires: python-setuptools
-
Requires: python-jdcal
-
# for embedded image support
-
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
#BuildRoot: %{_tmppath}/%{name}-%{version}-build
-
BuildArch: noarch
-
-
%description
-
openpyxl is a pure python reader and writer of Excel OpenXML files.
-
It is ported from the PHPExcel project
-
-
%prep
-
%setup -q -n openpyxl-%{version}
-
-
%build
-
#python setup.py build
-
CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
-
-
%install
-
#python setup.py install --prefix=%{_prefix} --root=%{buildroot}
-
%{__python} setup.py install -O1 --skip-build --root %{buildroot}
-
#mv LICENCE LICENSE
-
-
%clean
-
rm -rf %{buildroot}
-
-
%files
-
%defattr(-,root,root,-)
-
%{python_sitelib}/*
-
-
%changelog
-
* Mon Jan 5 2015 lll - 2.1.4-0
-
- This spec edit from an suse spec file Update to feature release 2.1.4
-
-
* Thu Jul 17 2014 toddrme2178@gmail.com
-
- Add LICENSE to %%doc
-
* Thu Dec 5 2013 p.drouand@gmail.com
-
- Update to version 1.7.0
-
+ Read CHANGES file from package documentation
-
* Thu Oct 24 2013 speilicke@suse.com
-
- Require python-setuptools instead of distribute (upstreams merged)
-
* Fri May 10 2013 toddrme2178@gmail.com
-
- Initial version
这样两个python-openpyxl的rpm包及依赖包就做好了
其他机器需要python-openpyxl的直接安装rpm包即可,不需要安装setuptools
更新下, Requires项目点setup.py里有,对应的文档里也有
阅读(3490) | 评论(0) | 转发(0) |