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.
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 .
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
make
make install
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
All steps here are done in Ubuntu, not the development board .
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.
Install crossenv:pip3 install crossenv
Use crossenv to represent the virtual environment of arm-python:python3 -m crossenv --without-pip /home/book/arm-python/bin/python3 cross_venv
cd cross_venv/cross/bin
Activate the virtual environment:source activate
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.
./python3 get-pip.py
Install Cython in the cross_venv virtual environment:./pip3 install Cython
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:
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 :
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.
4. Transplant to linux development board
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.
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
Verify pip3: ./pip3 list
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.