准备软件
确认按照以下步骤进行操作:
注: 该Python应用VisionFive.gpio适用于昉·星光单板计算机、昉·星光 2和昉·惊鸿7110 EVB。
- 按照《昉·星光 2单板计算机快速参考手册》中的“将OS烧录到Micro-SD”章节,将Debian OS烧录到Micro-SD卡上。
- 登录Debian并确保昉·星光 2已联网。有关详细说明,请参阅《昉·星光 2单板计算机快速参考手册》中“通过以太网使用SSH”或“使用USB转串口转换器”章节。
- 在Debian上扩展分区,请参见《昉·星光 2单板计算机快速参考手册》中“扩展分区”章节。
- 执行以下命令,在Debian系统上安装PIP:
apt-get install python3-pip
- 在昉·星光 2
Debian上执行
pip
命令,以安装VisionFive.gpio包:注: 由于pypi.org官网尚不支持上传RISC-V平台的whl安装包,不能直接使用pip install VisionFive.gpio
命令在线安装,因此请按照以下步骤安装VisionFive.gpio包。- 执行以下命令,安装依赖包:
apt install libxml2-dev libxslt-dev python3 -m pip install requests wget bs4
- 执行以下命令,运行安装脚本
Install_VisionFive_gpio.py
:python3 Install_VisionFive_gpio.py
安装脚本代码如下:import requests import wget import sys import os from bs4 import BeautifulSoup def parse_data(link_addr, class_type, key_str): req = requests.get(url=link_addr) req.encoding = "utf-8" html=req.text soup = BeautifulSoup(req.text,features="html.parser") package_version = soup.find(class_type,class_=key_str) dd = package_version.text.strip() data = dd.split() return data def parse_link(link_addr, class_type, key_str): req = requests.get(url=link_addr) req.encoding = "utf-8" html=req.text soup = BeautifulSoup(req.text,features="html.parser") search_data = soup.find(class_type,class_=key_str) search_data_2 = search_data.find("a") dl_link_get = search_data_2.get("href") return dl_link_get def get_dl_addr_page(): link_address = "https://pypi.org/project/VisionFive.gpio/#history" key_str = "release__version" class_key = "p" data_get = parse_data(link_address, class_key, key_str) latest_version = data_get[0] dl_addr_page = "https://pypi.org/project/VisionFive.gpio/{}/#files".format(latest_version) return dl_addr_page def get_dl_addr_of_latest_version(link_addr): key_str = "card file__card" class_key = "div" addr_get = parse_link(link_addr, class_key, key_str) return addr_get def main(): dl_addr_p = get_dl_addr_page() whl_dl_addr = get_dl_addr_of_latest_version(dl_addr_p) whl_name = whl_dl_addr.split("/")[-1] whl_name_suffix = os.path.splitext(whl_name)[-1] whl_name_prefix = os.path.splitext(whl_name)[0] whl_name_prefix_no_platform = whl_name_prefix[0: len(whl_name_prefix) - 3] new_platform = "linux_riscv64" rename_whl_name = "{}{}{}".format(whl_name_prefix_no_platform, new_platform, whl_name_suffix) wget.download(whl_dl_addr, out=rename_whl_name) os.system("pip install " + rename_whl_name) os.system("rm -rf " + rename_whl_name) if __name__ == '__main__': sys.exit(main())
- 执行以下命令,安装依赖包: