6

I am writing a custom yocto recipe that should install a python package from a .whl file.

I tried it using a recipe that contains:

inherit pypi setuptools
PYPI_SRC_URI="http://ci.tensorflow.org/view/Nightly/job/nightly-pi-zero/lastSuccessfulBuild/artifact/output-artifacts/tensorflow-1.5.0rc1-cp27-none-any.whl“

But it does not work that way, it states, that a setup.py file is missing and when trying to write a custom do_compile task that runs pip install <PATH-TO-WHL> it says, that pip is an unkown command.

When installing .whl files directly onto the target system one would type the following:

pip install <path-to-whl-file>

Thanks for your help!

Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17
Mathias
  • 61
  • 1
  • 3

2 Answers2

9

.whl package is just a .zip file with python sources, and precompiled binaries for certain platform.

So, you can do something like this:

COMPATIBLE_HOST = "i686.*-mingw.*"                                                                  

SRC_URI = "https://files.pythonhosted.org/packages/d8/9d/7a8cad803ef73f47134ae5c3804e20b54149ce62a7d1337204f3cf2d1fa1/MarkupSafe-1.1.1-cp35-cp35m-win32.whl;downloadfilename=MarkupSafe-1.1.1-cp35-cp35m-win32.zip;subdir=${BP}"

SRC_URI[md5sum] = "a948c70a1241389d7120db90d69079ca"                                                
SRC_URI[sha256sum] = "6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1"             

inherit nativesdk python3-dir                                                                       

LICENSE = "BSD-3-Clause"                                                                            

PV = "1.1.1"                                                                                        
PN = "nativesdk-python3-markupsafe"                                                                 

LIC_FILES_CHKSUM = "file:///${S}/MarkupSafe-1.1.1.dist-info/LICENSE.rst;md5=ffeffa59c90c9c4a033c7574f8f3fb75"

do_unpack[depends] += "unzip-native:do_populate_sysroot"                                            

PROVIDES += "nativesdk-python3-markupsafe"                                                          
DEPENDS += "nativesdk-python3"                                                                      

FILES_${PN} += "\                                                                                   
    ${libdir}/${PYTHON_DIR}/site-packages/* \                                                       
"                                                                                                   

do_install() {                                                                                      
    install -d ${D}${libdir}/${PYTHON_DIR}/site-packages/MarkupSafe-1.1.1.dist-info                 
    install -d ${D}${libdir}/${PYTHON_DIR}/site-packages/markupsafe                                 

    install -m 644 ${S}/markupsafe/* ${D}${libdir}/${PYTHON_DIR}/site-packages/markupsafe/          
    install -m 644 ${S}/MarkupSafe-1.1.1.dist-info/* ${D}${libdir}/${PYTHON_DIR}/site-packages/MarkupSafe-1.1.1.dist-info/
}

I haven't tested it, yet, but it already forms proper nativesdk package. Note downloadfilename= parameter to the SRC_URI - without it, .whl file would not be extracted.

fhunter
  • 101
  • 1
  • 4
2

Basing on https://stackoverflow.com/a/57694762/5422708 answer I would like to share working recipe for engineering_notation 0.6.0 module which also provides only .whl package:

SUMMARY = "To easily work with human-readable engineering notation."
HOMEPAGE = "https://github.com/slightlynybbled/engineering_notation"

SRC_URI = "https://files.pythonhosted.org/packages/d4/c4/4712b8020b8a3ada129581be891e2dbbd6a4cf54195ea2b80f89bbc51756/engineering_notation-${PV}-py3-none-any.whl;downloadfilename=engineering_notation-${PV}-py3-none-any.zip;subdir=${BP}"

SRC_URI[md5sum] = "5684efec41bc0738bb1fe625a71ffaf7"
SRC_URI[sha256sum] = "1ea1e450d575b4804723d0711b0609d2711dffac2f4b5548ee632c16a636d9f6"

inherit python3-dir

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file:///${S}/engineering_notation-${PV}.dist-info/METADATA;md5=5a9ae92d9fbf02bbcd5e4e94e6356cd3"

do_unpack[depends] += "unzip-native:do_populate_sysroot"

DEPENDS += "python3"

FILES:${PN} += "\
    ${libdir}/${PYTHON_DIR}/site-packages/engineering_notation \
    ${libdir}/${PYTHON_DIR}/site-packages/engineering_notation-${PV}.dist-info \
"

do_install() {
    install -d ${D}${libdir}/${PYTHON_DIR}/site-packages/engineering_notation
    install -d ${D}${libdir}/${PYTHON_DIR}/site-packages/engineering_notation-${PV}.dist-info

    install -m 644 ${S}/engineering_notation/* ${D}${libdir}/${PYTHON_DIR}/site-packages/engineering_notation/
    install -m 644 ${S}/engineering_notation-${PV}.dist-info/* ${D}${libdir}/${PYTHON_DIR}/site-packages/engineering_notation-${PV}.dist-info/
}
b1czu
  • 46
  • 3