构建Python包

4
我正在使用BitBake编译一些Python库,在添加第二个库时出现了以下警告:
WARNING: The recipe is trying to install files into a shared area when those files already exist. Those files are:
   /home/ilya/beaglebone-dany/build/tmp/sysroots/beaglebone/usr/lib/python2.7/site-packages/site.py
   /home/ilya/beaglebone-dany/build/tmp/sysroots/beaglebone/usr/lib/python2.7/site-packages/site.pyo

这两个库都使用了inherit distutils。对于bitbake来说这是可以的,但当我尝试通过opkg安装第二个包时,我遇到了以下错误:
# opkg install http://yocto.local:8080/python-requests_1.2.0-r0_armv7a-vfp-neon.ipk
Downloading http://yocto.local:8080/python-requests_1.2.0-r0_armv7a-vfp-neon.ipk.
Installing python-requests (1.2.0-r0) to root...
Configuring python-requests.

# opkg install http://yocto.local:8000/python-mylib_0.0.1-r0_armv7a-vfp-neon.ipk
Downloading http://yocto.local:8080/python-mylib_0.0.1-r0_armv7a-vfp-neon.ipk.
Installing python-mylib (0.0.1-r0) to root...
Collected errors:
 * check_data_file_clashes: Package mylib-python wants to install file /usr/lib/python2.7/site-packages/site.py
        But that file is already provided by package  * python-requests
 * check_data_file_clashes: Package mylib-python wants to install file /usr/lib/python2.7/site-packages/site.pyo
        But that file is already provided by package  * python-requests
 * opkg_install_cmd: Cannot install package mylib-python.

这两个配方看起来都是这样的:

DESCRIPTION = "Requests: HTTP for Humans"
HOMEPAGE = "http://docs.python-requests.org/en/latest/"
SECTION = "devel/python"
LICENSE = "Apache-2.0"

DEPENDS = "python"
RDEPENDS_${PN} = "python-core"
PR = "r0"

SRC_URI = "git://github.com/kennethreitz/requests;protocol=git"

S = "${WORKDIR}/git/"

inherit distutils

#NOTE: I'm not 100% sure whether I still need to export these?
export BUILD_SYS
export HOST_SYS
export STAGING_INCDIR
export STAGING_LIBDIR

BBCLASSEXTEND = "native"

我从pycurl配方中复制了这个内容,该配方也有这几行代码,但我已将其删除:

do_install_append() {
    rm -rf ${D}${datadir}/share
}
1个回答

5
为了避免冲突的/usr/lib/python2.7/site-packages/site.py,需要通过以下方式避免此文件的出现:
do_install_append() {
  rm -f ${D}${libdir}/python*/site-packages/site.py*
}

原始版本的食谱存在问题,它安装的文件仅包含 `.egg` 目录。我无法导入生成的软件包。
结果发现,使用 `inherit setuptools` 而非 `inherit distutils` 则可以解决此问题。
虽然我不是 Python 专家,但所有 `setuptools class` 的功能就是这样。详情请参见 setuptools 类
inherit distutils

DEPENDS += "python-setuptools-native"

DISTUTILS_INSTALL_ARGS = "--root=${D} \
    --single-version-externally-managed \
    --prefix=${prefix} \
    --install-lib=${PYTHON_SITEPACKAGES_DIR} \
    --install-data=${datadir}"

原来有些模块(例如PyBBIO)无法识别--single-version-externally-managed,所以您需要使用inherit distutils才能获得可用的软件包。
下面是完整的python-requests软件包配方,它很快就会在上游发布,如果您打算使用它,请参考。
DESCRIPTION = "Requests: HTTP for Humans"
HOMEPAGE = "http://docs.python-requests.org/en/latest/"
SECTION = "devel/python"
LICENSE = "Apache-2.0"

#DEPENDS = "python-core"
RDEPENDS_${PN} = "python"
PR = "r0"

SRC_URI = "git://github.com/kennethreitz/requests;protocol=git"

S = "${WORKDIR}/git/"

inherit setuptools

# need to export these variables for python-config to work
export BUILD_SYS
export HOST_SYS
export STAGING_INCDIR
export STAGING_LIBDIR

BBCLASSEXTEND = "native"

do_install_append() {
  rm -f ${D}${libdir}/python*/site-packages/site.py*
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接