本帖最后由 水精灵 于 2024-1-24 16:55 编辑
python下载网址:https://www.python.org/ftp/python/
Linux4.1.15 emmc版默认支持python2.7,若需其它版本的python,可以进行交叉移植。本篇文章以python3.6.9为例,在网址下载Python-3.6.9.tar.xz压缩文件。
1.拷贝Python-3.6.9.tar.xz到开发环境/home/elf/work目录下解压:
elf@ubuntu:~/work$ tar xvf Python-3.6.9.tar.xz
2.进入Python-3.6.9目录:
elf@ubuntu:~/work$ cd Python-3.6.9/
3.创建新目录:
elf@ubuntu:~/work/Python-3.6.9$ mkdir build-arm
4.虚拟机安装python3.6.9:
(1)编译:
elf@ubuntu:~/work/Python-3.6.9$ ./configure
elf@ubuntu:~/work/Python-3.6.9$ make
elf@ubuntu:~/work/Python-3.6.9$ sudo make install
编译报错,执行如下命令:
elf@ubuntu:~/work/Python-3.6.9$ sudo apt-get install zlib*
再次sudo make install,编译成功。
(2)清除编译临时生成的中间文件,为交叉编译做准备:
elf@ubuntu:~/work/Python-3.6.9$ sudo make clean
5.交叉编译python:
(1)进入build-arm目录:
elf@ubuntu:~/work/Python-3.6.9$ cd build-arm/
(2)设置交叉编译环境变量:
elf@ubuntu:~/work/Python-3.6.9/build-arm$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
(3)设置CONFIG_SITE环境变量:
elf@ubuntu:~/work/Python-3.6.9/build-arm$ echo ac_cv_file__dev_ptmx=no > config.site
elf@ubuntu:~/work/Python-3.6.9/build-arm$ echo ac_cv_file__dev_ptc=no >> config.site
elf@ubuntu:~/work/Python-3.6.9/build-arm$ export CONFIG_SITE=config.site
(4)交叉编译:
elf@ubuntu:~/work/Python-3.6.9/build-arm$ ../configure --host=arm-poky-linux-gnueabi --build=x86_64-linux-gnu --prefix=$PWD/_install --disable-ipv6
elf@ubuntu:~/work/Python-3.6.9/build-arm$ make
elf@ubuntu:~/work/Python-3.6.9/build-arm$ make install
编译报错,执行如下命令:
elf@ubuntu:~/work/Python-3.6.9/build-arm$ sudo rm /usr/bin/lsb_release
再次make install编译,在_install目录下会生成bin、include、lib、share文件夹。
6.移植交叉编译好的python到ARM开发板:
(1)在_install目录下打包所有目录:
elf@ubuntu:~/work/Python-3.6.9/build-arm/_install$ tar cvf python3.6.tar.bz2 ./
(2)将生成的压缩包文件放到开发板文件系统根目录下进行解压:
root@ELF1:~# cd /
root@ELF1:/# cp /run/media/sda1/python3.6.tar.bz2 .
root@ELF1:/# tar xvf python3.6.tar.bz2
(3)设置环境变量:
root@ELF1:/# export PYTHONPATH=$PYTHONPATH:/lib/python3.6
root@ELF1:/# export PYTHONHOME=$PYTHONHOME:/lib/python3.6
(4)运行测试:
root@ELF1:/# python3.6
Python 3.6.9 (default, Nov 10 2023, 03:00:36)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'3.6.9 (default, Nov 10 2023, 03:00:36) \n[GCC 5.3.0]'
按ctrl+d可退出python。
测试无误,python3.6.9移植成功。
|
|