Deploying Python Code to Unitree G1
A step-by-step guide to pushing and running your custom Python scripts (Unitree SDK) on the Unitree G1 EDU robot.
Prerequisites
Before you begin, ensure you have the following:
Target Robot IP:
192.168.123.164Username:
unitreePassword:
123Robot State: Ensure the robot is in Development Mode.
Step 1: Locate your Script
Identify the local path of the Python script you wish to deploy. In this example, we are using:
C:\Users\wahee\OneDrive\Desktop\1768287590424-last_piano_before_bed_script.pyStep 2: Transfer the File (SCP)
Use the scp (Secure Copy) command to push the file from your local machine to the robot. Open your terminal (PowerShell or Command Prompt) and run:
scp \"C:\Users\wahee\OneDrive\Desktop\1768287590424-last_piano_before_bed_script.py\" unitree@192.168.123.164:~/Note: You will be prompted to enter the password (123) after running this command.
Step 3: Connect and Install SDK
SSH into the robot and install the unitree_sdk2_python library.
Note: The robot needs an internet connection to install packages. If sudo apt update fails, follow the Internet Setup section below.
ssh unitree@192.168.123.164
# Install dependencies
sudo apt update && sudo apt install -y python3-pip git
pip3 install cyclonedds==0.10.2 numpy opencv-python
# Clone and install Python SDK
git clone https://github.com/unitreerobotics/unitree_sdk2_python.git
cd unitree_sdk2_python
pip3 install .Step 4: Execute the Code
Since your script uses the Unitree SDK directly (not a ROS2 node), you can run it with standard Python:
python3 ~/1768287590424-last_piano_before_bed_script.pyNote: Ensure the robot's arms are clear of obstacles before running!
Troubleshooting: Internet Connection
If the robot fails to install updates or packages, it likely lacks internet access. Choose one of the following methods to get it online.
Option 1: Connect via Wi-Fi (Recommended)
The G1 has built-in Wi-Fi that can be enabled via SSH.
# 1. Enable Wi-Fi
sudo nmcli radio wifi on
# 2. Scan for networks
sudo nmcli dev wifi list
# 3. Connect (Replace with your details)
sudo nmcli dev wifi connect "Your_WiFi_Name" password "Your_Password"
# 4. Test connection
ping google.comOption 2: Share Windows Internet over Ethernet
If Wi-Fi is unavailable, you can share your PC's internet connection through the Ethernet cable.
On Windows: Go to Control Panel > Network and Sharing Center > Change adapter settings. Right-click your Wi-Fi adapter > Properties > Sharing tab. Check "Allow other network users to connect..." and select the Ethernet adapter connected to the robot.
Fix IP: This may reset your Ethernet IP. Manually set it back to
192.168.123.161(IPv4 Properties) so you can still SSH.On Robot (SSH): Configure the gateway and DNS to route traffic through your PC.
# Set Gateway to your PC's IP sudo route add default gw 192.168.123.161 # Set DNS echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf