PYTHON3.7.6交叉编译&本地编译

1.准备号依赖库

  如zlib readline openssl ncurses等等

编译脚本

#!/bin/bash
set -e


ROOT_DIR=/home/xxx/test/ins_py3
BASE_PATH=/home/xxx/test/usr

export CC=arm-fsl-linux-gnueabi-gcc
export CXX=arm-fsl-linux-gnueabi-g++
export AR=arm-fsl-linux-gnueabi-ar
export RANLIB=arm-fsl-linux-gnueabi-ranlib
export LD=arm-fsl-linux-gnueabi-ld
#export STRIP=arm-linux-gnueabi-strip
#export STRINGS=arm-linux-gnueabi-strings
export READELF=arm-fsl-linux-gnueabi-readelf


export CFLAGS="-I$BASE_PATH/include"
export CPPFLAGS="-I$BASE_PATH/include"
export LDFLAGS="-L$BASE_PATH/lib"

./configure --prefix=/usr --build=arm --host=arm-linux --disable-ipv6 ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=yes

make 

make install DESTDIR=$ROOT_DIR

ubuntu16.04

sudo apt-get install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev

Python 2.7.17转换为Python 3.7.6需要进行以下步骤: 1. 安装Python 3.7.6 首先需要下载Python 3.7.6的安装包,可以从官网(https://www.python.org/downloads/release/python-376/)下载。下载后双击安装包进行安装,并将Python 3.7.6添加到环境变量中。 2. 检查Python 2代码 在转换之前,需要检查Python 2代码是否有兼容性问题。可以使用2to3工具来检查代码并进行转换。2to3是Python自带的工具,可以在终端中执行以下命令来进行检查: ``` 2to3 -n -w /path/to/your/python/files ``` 参数说明: -n:不进行备份 -w:直接进行修改 /path/to/your/python/files:Python代码所在的目录或文件路径 检查修改后的代码是否能够正常运行。 3. 修改代码 在进行代码转换时,需要进行以下修改: 3.1 print语句 在Python 2中,print是一个语句,而在Python 3中,print是一个函数,需要使用括号将参数括起来。例如: ``` # Python 2 print "Hello, World!" # Python 3 print("Hello, World!") ``` 3.2 字符串 在Python 2中,字符串默认使用ASCII编码,而在Python 3中,默认使用Unicode编码。因此在Python 3中,字符串需要使用单引号或双引号将其括起来。例如: ``` # Python 2 s = 'Hello, World!' # Python 3 s = "Hello, World!" ``` 3.3 input函数 在Python 2中,input函数会将输入的内容当做Python代码来执行,而在Python 3中,input函数只会当做字符串来处理。因此在Python 3中,需要使用eval函数来将输入的字符串转换为Python代码。例如: ``` # Python 2 name = raw_input("What's your name? ") # Python 3 name = eval(input("What's your name? ")) ``` 3.4 xrange函数 在Python 2中,xrange函数返回一个生成器对象,而在Python 3中,range函数返回一个可迭代对象。因此在Python 3中,需要使用range函数来替代xrange函数。例如: ``` # Python 2 for i in xrange(10): print i # Python 3 for i in range(10): print(i) ``` 4. 测试代码 修改代码后,需要进行测试以确保代码能够正常运行。可以使用unittest模块来进行测试。创建一个测试文件,将测试用例放入其中,并执行测试文件。例如: ``` import unittest class TestStringMethods(unittest.TestCase): def test_upper(self): self.assertEqual('foo'.upper(), 'FOO') def test_isupper(self): self.assertTrue('FOO'.isupper()) self.assertFalse('Foo'.isupper()) def test_split(self): s = 'hello world' self.assertEqual(s.split(), ['hello', 'world']) # check that s.split fails when the separator is not a string with self.assertRaises(TypeError): s.split(2) if __name__ == '__main__': unittest.main() ``` 5. 进行调试 如果代码在Python 3中仍然无法运行,可以使用调试工具来进行调试。可以使用pdb或ipdb工具来进行调试。例如: ``` import pdb def test(x): result = x * 2 pdb.set_trace() return result print(test(3)) ``` 执行以上代码后,程序会停在pdb.set_trace()的位置,可以使用pdb的命令来进行调试。例如,输入p result可以查看result变量的值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值