ZYNQ-Linux development (eight) Python source code cross-compilation installation and the use of Numpy library cross-compilation installation

  • Python source code cross compilation

For the zynq platform, the format of the library file directly compiled by the zynq board is a hard floating point type, and when the library file is referenced in eclipse , it needs a soft floating point type, so the library file directly compiled by the zynq platform development board is If it cannot be cross-compiled and used in eclipse , it will prompt an error that the VFP format is incorrect. There are two ways to solve this problem. One is to cross-compile the library source code in the virtual machine through a cross-compilation tool, so that the compiled library file is a soft floating-point type. The other is to compile on the board, modify the compilation options, and put The hard floating-point compilation is changed to soft floating-point compilation. For the second method, the Makefile of some library source codes does not support soft and hard floating-point compilation, and can only be cross-compiled in a virtual machine. At the same time, not every platform board is compiled with hard floating point by default. For example, the library files compiled by the LS2088 platform board can be directly called in eclipse by default, and VFP format errors will not occur .

Before cross-compiling the Python source code, it is necessary to compile the source code for the PC version, that is, compile for the X86 platform.

PC version compilation process:

  1. Put the source code compressed package in any path and decompress the source code: tar -xvf Python-3.4.0.tgz
  2. Enter the source code directory: cd Python-3.4.0/
  3. Execute configure to configure the Makefile :

./configure --prefix=/home/daisy/python/python3.4pc

--prefix= is followed by the path where the PC version of Python is to be installed

The following interface appears, proving that the Makefile is successfully generated

  1. Compile the source code and execute: make

The following interface appears to prove that the compilation passed

  1. To install the PC version of Python, execute: make install

ARM version cross compilation process:

  1. Enter the following commands in sequence on the console:

echo ac_cv_file__dev_ptmx=yes > config.site

echo ac_cv_file__dev_ptc=yes >> config.site

export CONFIG_SITE=config.site

export CXX=arm-xilinx-linux-gnueabi-g++

export CC=arm-xilinx-linux-gnueabi-gcc

  1. Execute configure to configure the Makefile :

./configure --prefix=/home/daisy/python/python34 --host=arm-xilinx-linux-gnueabi --build=x86_64-pc-linux-gnu --enable-shared --disable-ipv6

--prefix= is followed by the path where the ARM version of Python is to be installed

--host= is the target platform

--build= is the current compiled platform

--enable-shared is to generate .so dynamic library, --disable-shared is to generate .a static library

The following interface appears, proving that the Makefile is successfully generated

  1. To clear the files compiled by the PC version, execute: make clean
  2. Compile the source code and execute: make

The following interface appears to prove that the compilation passed

  1. To install the ARM version of Python, execute: make install

For the 3.4.0 version, the following error will appear after installation, mainly because the 3.4 version does not have pip, and if the higher version comes with a pip tool, no error will be reported, and the error report should be ignored.

  1. After the compilation is successful, the following four folders will appear in the installation directory:

bin: python executable program

include: python interface function header file

lib: python interface function library (.a and .so)

share: not used for cross-compilation

So far, the files required to reference the python interface functions in the code have been compiled.

  • Install the numpy library

For the numpy library used for cross-compilation, only the .h file under the numpy folder is needed, so the numpy library called in eclipse does not need to be cross-compiled. Copy the usr/lib/python3/dist-packages/numpy/core/include/numpy folder and put it in the virtual machine for use. You can also manually install the numpy library on the X86 platform or the numpy library on the ARM platform, and then install python corresponding to the directory

The lib/python3.4/site-packages/numpy/core/include/numpy folder can also be copied and used, but the executable program compiled by C++ must have the numpy library installed on the running board or platform , and can be loaded and used, because the cross-compiled program depends on the numpy library on the running platform. The following first explains how to install the numpy library on the X86 platform.

Install the numpy library on the X86 platform :

Before installing the numpy library, you need to install Python first, and the steps are the same as the compilation process of the PC version in the first part above.

  1. Unzip the numpy source code: tar –xvf numpy-1.8.1.tar.gz
  2. Enter the numpy source path: cd numpy-1.8.1/
  3. Install the numpy library through Python and execute the command:

../python3.4pc/bin/python3.4 setup.py install

Among them, ../python3.4pc/bin/python3.4 is the installation path of the PC version of Python. You need to call the Python executable program to install the numpy library. After the installation is successful, it will be in the lib/python3.4pc/site- Generate numpy library related content under packages/.

  1. Verify that the numpy library installation was successful:

Go to the bin folder of the Python installation directory: cd python3.4pc/bin

Start the Python program: ./python3.4

Load the numpy library: import numpy

If the content shown in the figure above appears and no error is reported, it proves that the numpy library has been loaded.

It should be noted that the Python version needs to correspond to the numpy version. If the version does not correspond, the numpy library cannot be used. There is a corresponding description of the numpy library on the official website. For example, if it is written with cp34 , it can correspond to the Python3.4 version. If the version of Python and the device is connected to the Internet, you can directly use the pip tool to install the numpy library. The default is the numpy library version applicable to the current Python .

  • The development board ARM platform directly compiles Python and numpy libraries

The development board directly compiles the Python source code in the same way as the PC side. There is no cross-compilation tool, compilation platform, target platform and other configurations. You can directly compile with gcc . The development board compiles very slowly, and it takes about half an hour.

Install Python source code:

  1. Put the source code compressed package in any path and decompress the source code: tar -xvf Python-3.4.0.tgz
  2. Enter the source code directory: cd Python-3.4.0/
  3. Execute configure to configure the Makefile :

./configure --prefix=/home/analog/python3.4

--prefix= is followed by the path where Python is to be installed

The following interface appears, proving that the Makefile is successfully generated

  1. Compile the source code and execute: make

The following interface appears to prove that the compilation passed

  1. To install Python, execute: make install

Install the numpy library:

  1. Unzip the numpy source code: tar –xvf numpy-1.8.1.tar.gz
  2. Enter the numpy source path: cd numpy-1.8.1/
  3. Install the numpy library through Python and execute the command:

../python3.4/bin/python3.4 setup.py install

Among them, ../python3.4/bin/python3.4 is the path of Python installation. You need to call the Python executable program to install the numpy library. After the installation is successful, it will be in the lib/python3.4/site-packages/ of the Python installation directory. Generate numpy library related content below.

  1. Verify that the numpy library installation was successful:

Go to the bin folder of the Python installation directory: cd python3.4pc/bin

Start the Python program: ./python3.4

Load the numpy library: import numpy

If the content shown in the figure above appears and no error is reported, it proves that the numpy library has been loaded.

  • How to switch the default python version
  1. The development board switches the default version of Python

The system startup will call the python soft link in the /usr/bin/ directory by default. You only need to point the soft link to a different version of the Python executable program, for example:

ln -s /home/analog/python3.4/bin/python3.4 ./python

This creates a soft link. It should be noted that the existing soft link must be deleted before creation, and the executable program needs to be given permission to run.

  1. The virtual machine switches the default version of Python

If anaconda is not installed in the virtual machine, the switching method is the same as that of the development board. If anaconda is installed, you need to modify the .bashrc file in the user folder, open the file and find the end, comment out the part, open the command window, and execute: source ~/.bashrc (or restart the virtual machine), turn off anaconda's Python, and you can switch versions by modifying the Python soft link under /usr/bin/.

View the contents of the .a static library:

ar -t python3.4m.a

Package static library:

ar -cvr python3.4m.a *.o

Package dynamic library:

gcc -shared -o python3.4m.so python.o

gcc -shared -o libhiredis.so alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o

Guess you like

Origin blog.csdn.net/qq_38584212/article/details/132041971