|
迅為-iMX6ULL開發(fā)板-Python移植-運(yùn)行測(cè)試2 92.3.1 庫(kù)功能文件測(cè)試 進(jìn)入_install/bin 目錄下使用命令./python,然后使用 import 加載各模塊如圖 92.3.1.1 所示則 python移植成功。按 ctrl+D 退出。
92.3.2 數(shù)據(jù)庫(kù)測(cè)試 在提供的壓縮包里提供的有 sqlite3 數(shù)據(jù)庫(kù)的例程 sqlite3test.txt,例程解釋如下。 import sqlite3 #導(dǎo)入 SQLite 驅(qū)動(dòng) conn = sqlite3.connect('test.db') #連接到 SQLite 數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)文件是 test.db,如果文件不存在,會(huì)自動(dòng)在當(dāng)前目錄創(chuàng)建 print "Opened database successfully" cursor = conn.cursor() #創(chuàng)建一個(gè) Cursor cursor.execute('create table user (id varchar(20) primary key, name varchar(20))') #執(zhí)行一條 SQL 語(yǔ)句,創(chuàng)建 user 表 cursor.execute('insert into user (id, name) values (\'1\', \'Michael\')') #執(zhí)行一條 SQL 語(yǔ)句,插入一條記錄 cursor.execute('insert into user (id, name) values (\'2\', \'jack\')') print "Records created successfully" cursor.rowcount #通過 rowcount 獲得插入的行數(shù) cursor.close() #關(guān)閉 Currsor conn.commit() #提交事務(wù) conn.close() #關(guān)閉 Connection 執(zhí)行命令”./python sqlite3test.txt” 可以看到生成了數(shù)據(jù)庫(kù)文件 test.db 文件。
92.3.3 time 和 和 datetime 測(cè)試 我們可以先調(diào)整時(shí)間:“date -s "2020-07-21 16:02:00" && hwclock --systohc” 在提 供的壓縮 包里提供 的有 time 測(cè)試 的例程 timetest.txt,將 測(cè)試?yán)?拷貝到開 發(fā)板的/data/_install/bin 下,執(zhí)行命令“./python timetest.txt”可完成時(shí)間格式的轉(zhuǎn)換和微秒級(jí)時(shí)間差的計(jì)算。
以上步驟無(wú)誤后將環(huán)境變量添加到/etc/profile 文件: export LD_LIBRARY_PATH=/data/_install/lib LD_LIBRARY_PATH
92.3.4 sqlite3 庫(kù)的移植 本章將制作 2.4 章節(jié)用到的 install_python 文件。和本文檔同目錄下有數(shù)據(jù)庫(kù)的壓縮包,也可以去 sqlite官網(wǎng)下載最新的數(shù)據(jù)庫(kù),通過 ssh 拷貝到 /home/ubuntu/python/ 目錄下,使用命令“tar -vxfsqlite-autoconf-3240000.tar.gz ”解壓,解壓后生成文件夾“sqlite-autoconf-3240000” 如圖 92.3.4.1 所示:
進(jìn)入解壓后生成的文件夾“sqlite-autoconf-3240000”,執(zhí)行命令“./configure --host=arm-none-linux-gnueabi --prefix=/home/ubuntu/python/sqlite-autoconf-3240000/install_python--enable-shared”,成功后生成 Makefile 等文件,如圖 92.3.4.2。
執(zhí)行 make 編譯,成功后如圖 92.3.4.3:
執(zhí)行命令“make install”,會(huì)看到在 sqlite-autoconf-3240000 目錄下產(chǎn)生文件夾 install_python,執(zhí)行命令“l(fā)s install_python”可以看到目錄下有:bin include lib 三個(gè)文件夾。
至此 sqlite3 的庫(kù)已經(jīng)編譯完成,用戶需要其他的庫(kù)文件也可以照此編譯。
|