1529 views|2 replies

274

Posts

8

Resources
The OP
 

[Sipeed LicheeRV 86 Panel Review] 5-Porting Python3 to the Development Board [Copy link]

 This post was last edited by manhuami2007 on 2022-4-6 10:24

LicheeRV 86 can be programmed using C and C++. Some codes are difficult to write, so I thought of porting Python to the board. After many days of hard work, Python 3.8 was successfully ported to the development board. Now I will share the porting process.

The main code of Python is also written in C/C++, so Python can be compiled into a version that can be used by the development board through cross compilation. After the compilation is completed, an executable file and the corresponding lib will be generated.

By adding the executable file to the PATH variable and the library path to the LD_LIBRARY_PATH variable, you can implement the python function.

So the point is how to generate executable files and libraries.

1. Download Python source code

The official website of Python provides a way to download the source code. After downloading, unzip it to get the required source code. I chose Python 3.8.13.

2. Configure Python compilation method

2.1 Set the variables corresponding to the compilation tool

When compiling Python, you need to specify the compilation tools required for compilation, which CC, CXX, ARare introduced through variables, etc.

These tools have been configured when configuring the cross-compilation environment of the development board, so they can be used directly after the environment is configured.

Note that before use, you must enable the variables of the development board compilation tool through the source command.

2.2 Create a folder

Create a folder in the root directory of the source code to store some intermediate files generated by compilation.

mkdir riscv.build

2.3 Configure compilation parameters

Configure the compilation parameters through the following instructions:

../configure --prefix=/Python3.8.13 --build=riscv64-linux-gnu --host=riscv64-linux --target=riscv64-linux-gnu --enable-shared --enable-ipv6 --with-system-ffi ac_cv_file__dev_ptmx=0 ac_cv_file__dev_ptc=0 --enable-optimizations

I don’t quite understand the above parameters. If you are interested, you can refer to this website: https://docs.python.org/zh-cn/3.10/using/configure.html

Note that if you want to configure python 3.8.13, you need to first install python 3.8 on your computer to successfully configure it , otherwise an error will be reported. The error reported at the time was not recorded, so I won't post the picture here.

3. Generate relevant files and import them into the development board

Then call the command

make
sudo make install

The compilation time will be long. After the compilation is completed, a Python3.8.13 folder will be generated in the root directory. This folder contains all the necessary things. Copy the contents of this folder to the development board, and then add the path of the python executable file and the path of the lib to the two variables PATH and LD_LIBRARY_PATH, and you can use it.

The way to add is to modify the /etc/profile file and add

export PATH=$PATH:/usr/python3.8/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/python3.8/lib

Then use the source command to make it effective.

source /etc/profile

Now you can use python3 commands.

4. Effect

Use python3 to open the python command line in the terminal.

[attach ]598160[/attach][attach]598 160[/attach][attach]598160[ /attach][attach]598160[/attach ]

The compiled folder is nearly 300M, and I don’t have permission to upload it. You can try to compile it yourself.

This post is from Domestic Chip Exchange

Latest reply

Awesome OP, thanks for sharing.   Details Published on 2022-4-6 12:42
 
 

155

Posts

1

Resources
2
 

Awesome OP, thanks for sharing.

This post is from Domestic Chip Exchange

Comments

I am also a Linux beginner  Details Published on 2022-4-6 12:45
 
 
 

274

Posts

8

Resources
3
 
sonicfirr posted on 2022-4-6 12:42 The host is great, thank you for sharing.

I am also a Linux beginner

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list