Preparing Software

Make sure the following procedures are performed:

Note: The python project, VisionFive.gpio, is applicable for VisionFive, VisionFive 2, VisionFive 2 Lite, and JH-7110 EVB.
  1. Flash Debian OS into a Micro-SD card as described in the Flashing Fedora OS to a Micro-SD Card section in the VisionFive 2 Single Board Computer Quick Start Guide or VisionFive 2 Lite Single Board Computer Quick Start Guide.
  2. Log into the Debian and make sure VisionFive 2 or VisionFive 2 Lite is connected to the Internet. For detailed instructions, refer to the Using SSH over Ethernet or the Using a USB to Serial Converter section in the VisionFive 2 Single Board Computer Quick Start Guide or VisionFive 2 Lite Single Board Computer Quick Start Guide.
  3. Extend the partition on Debian as described in Extend Partition in the VisionFive 2 Single Board Computer Quick Start Guideor VisionFive 2 Lite Single Board Computer Quick Start Guide.
  4. Execute the following command to install and create a Python3 Virtual Environment on Debian:
    sudo apt install python3-venv
    python3 -m venv myvenv
    
    Note:

    You may rename “myvenv” according to your preference.

  5. Execute the pip command on VisionFive 2 or VisionFive 2 Lite Debian to install the VisionFive.gpio package:
    Note: Due to the fact that pypi.org official website does not yet support uploading whl installation packages for the RISC-V platform, so it cannot directly execute python3 -m pip install VisionFive.gpio command to install online.

    Please follow the steps below to install the VisionFive.gpio package.

    1. Execute the following command to install dependent package within the newly created virtual environment:
      sudo apt install libxml2-dev libxslt-dev 
      source ./myvenv/bin/activate
      python3 -m pip install requests wget bs4
      
    2. Execute the following command to run the installation script Install_VisionFive_gpio.py:
      python3 Install_VisionFive_gpio.py
      The installation script codes are as follows:
      import sys, os, requests
      
      PACKAGE = "VisionFive.gpio"
      PLATFORM = "linux_riscv64"
      
      def py_abi():
      return f"cp{sys.version_info.major}{sys.version_info.minor}"
      
      def fetch_latest_wheel():
      url = f"https://pypi.org/pypi/{PACKAGE}/json"
      data = requests.get(url).json()
      version = data["info"]["version"]
      files = data["releases"][version]
      abi = py_abi()
      for f in files:
      name = f["filename"]
      if name.endswith(".whl") and abi in name:
      return f["url"], name
      raise RuntimeError(f"No wheel found matching ABI {abi}")
      
      def rewrite_platform(name):
      base, ext = os.path.splitext(name)
      parts = base.split("-")
      parts[-1] = PLATFORM
      return "-".join(parts) + ext
      
      def download(url, path):
      with requests.get(url, stream=True) as r:
      r.raise_for_status()
      with open(path, "wb") as f:
      for chunk in r.iter_content(8192):
      f.write(chunk)
      
      def main():
      url, orig = fetch_latest_wheel()
      newname = rewrite_platform(orig)
      print(f"Downloading: {url}")
      download(url, newname)
      print("Installing...")
      os.system(f"pip install {newname}")
      os.remove(newname)
      print("Done.")
      return 0
      
      if name == "main":
      sys.exit (main())
    3. (Optional) Exit the Python3 Virtual Environment.
      deactivate