Embedded Linux development board, cross-compile python third-party library numpy through crossenv

1. Introduction

1.1 Brief description

  1. When using pip to install Python's third-party library on the ARM side, the development board needs to be able to access the external network. For details on how to access the Internet on the development board, please refer to the blog: Embedded Linux development board, connect to the computer through a network cable, share the computer wireless network, and access the external network
  2. Here I first cross-compile curl to request the web server. This is mainly used to download the pip tool. If your development board has the curl command, you don’t need to compile it; or you can directly download the corresponding pip package to the development board on the web page without using the curl command.
  3. This blog is equivalent to an extension of the previous work in ubuntu, based on the Qt platform, calling python files and cross-compiling to run on the embedded Linux development board . I only cross-compiled python before and did not compile python third-party libraries. So here it is already defaulted that you have cross-compiled python. My cross-compiled path is: /home/book/arm-python; the path of all my installation packages is /home/book/pyarm . So if you are not referring to the cross-compiled python on my blog, please modify the path that appears in the following command to the path related to cross-compiling python yourself .

1.2 Compilation background

  1. Cross-compilation tool chain: gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf
  2. ubuntu platform:ubuntu18.04.1 64bit
  3. Embedded linux development board kernel: NXP CORTEX-A7 IMX6ULL

1.3 Steps

  1. Cross compile curl
  2. Use crossenv to cross-compile python third-party library numpy
  3. Ported to linux development board

2. Cross-compile curl

  1. Download curl, https://curl.se/download.html . Here I use the latest version curl-7.87.0.
  2. Unzip: tar xzvf curl-7.87.0.tar.gz
  3. cd curl-7.87.0
  4. Configure the compilation environment: ./configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-zlib=/ home/book/arm-python --with-ssl=/home/book/arm-python --enable-shared --disable-threaded-resolver --prefix=$(pwd)/tmp Note: here curl depends on openssl
    and zlib. To cross-compile openssl and zlib, you can refer to the blog : In ubuntu, based on the Qt platform, call the python file, cross-compile it to the embedded linux development board and run it
  5. make
  6. make install
  7. Migrate all the contents in /home/book/pyarm/curl-7.87.0/tmp/ to the development board directory /home/book/arm-python. Because the directory of my cross-compiled python on the development board is /home/book/arm-python. Please modify it to your own directory.

3. Use crossenv to cross-compile python third-party library numpy

  1. All steps here are done in Ubuntu, not the development board .
  2. The ubuntu I use comes with python and python3. Generally, the installed virtual machine Ubuntu comes with python. If your virtual machine does not, please install python3 according to the virtual machine type. For example, just use the command on ubuntu sudo apt-get install python3.
  3. Install crossenv:pip3 install crossenv
  4. Use crossenv to represent the virtual environment of arm-python:python3 -m crossenv --without-pip /home/book/arm-python/bin/python3 cross_venv
  5. cd cross_venv/cross/bin
  6. Activate the virtual environment:source activate
  7. Download the pip installation package: curl https://bootstrap.pypa.io/pip/3.6/get-pip.py -o get-pip.py -k. Because the version of python3 in my ubuntu is 3.6, I downloaded get-pip.py in 3.6.
  8. ./python3 get-pip.py
  9. Install Cython in the cross_venv virtual environment:./pip3 install Cython
  10. Create requests.txt: vi requirements.txt, write numpy and version number in it. The version I downloaded here is 1.13.3, so I write:
    Insert image description here
  11. Cross-compile numpy into an installation package in .whl format: ./pip3 wheel --wheel-dir /home/book/arm-pylib -r requirements.txt. /home/book/arm-pylib is the storage path of the numpy package in .whl format. You can choose it arbitrarily.
    Note : Because high-performance numpy relies on the lapack and atlas libraries, when you directly use the pip3 command to cross-compile numpy, it will look for the lapack and atlas libraries, but I have not found a suitable method to cross-compile the lapack library here. I hope you know . Partners are generous with their advice . Fortunately, these two libraries are not mandatory for installing the NumPy package. That is, numpy compiled without relying on the lapack and atlas libraries functions normally, but the performance is slightly worse.
    The solution is to set the environment variable before pip3 compilation :
export BLAS=None
export BLAS=None
export ATLAS=None
./pip3 wheel --wheel-dir /home/book/arm-pylib -r requirements.txt
  1. result:
    Insert image description here
  2. Note that here we use crossenv to cross-compile the numpy third-party library's suffix is ​​linux_arm, and our target board is armv7l, so here we have to manually change numpy-1.13.3-cp36-cp36m-linux_arm.whl to numpy-1.13.3-cp36-cp36m-linux_armv7l.whl. Otherwise, an error will be reported. To view the Linux development board architecture, use the command on the development board command terminal: uname -a.
    Insert image description here

4. Transplant to linux development board

  1. Migrate numpy-1.13.3-cp36-cp36m-linux_armv7l.whl to the directory /home/book/arm-python/bin. Because the directory of my cross-compiled python on the development board is /home/book/arm-python/bin. Please modify it to your own directory.
  2. Download pip3:./curl https://bootstrap.pypa.io/pip/3.6/get-pip.py -o get-pip.py -k
  3. Install pip3: ./python3 get-pip.py
    An error will appear here :
    Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org ', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)) - skipping
    ERROR: Could not find a version that satisfies the requirement pip<22.0 (from versions: none)
    ERROR: No matching distribution found for pip<22.0

    means: Unable to obtain content from the web page https://pypi.org/simple/pip/ .
    Solution: Change to domestic mirror address .
    ./python3 get-pip.py -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
  4. Verify pip3: ./pip3 list
    Insert image description here
  5. Install numpy: ./pip3 install numpy-1.13.3-cp36-cp36m-linux_armv7l.whl -i http://pypi.douban.com/simple --trusted-host pypi.douban.com.
    Note : If you do not want to specify the image source for each installation, you can refer to the blog https://blog.csdn.net/qq591840685/article/details/116399374 to create a pip.conf file to specify the image source.
  6. Verify numpy:
    Insert image description here

5. Reference article links

  1. Error reported using pip: Could not fetch URL https://pypi.org/simple/selenium/: There was a problem confirming the ss
  2. curl cross compilation
  3. [Python Notes] How to compile a NumPy package that does not depend on lapack and atlas libraries
  4. Cross compilation of python and third-party libraries

Guess you like

Origin blog.csdn.net/m0_43443861/article/details/128526455