You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在Jupyter中运行Webots及如何完成安装配置?

Setting Up Webots with Jupyter Notebook/Lab

Hey there! I totally get why you'd prefer Jupyter's cell-by-cell execution for working with Webots—it's perfect for testing and iterating code snippets quickly. Let me walk you through the full setup and configuration steps to get Webots running smoothly in Jupyter.

Prerequisites

  • First, make sure you have Webots installed (any recent stable version works, but I recommend grabbing the latest release).
  • Have Jupyter Notebook/Lab set up on your machine—install it via pip install jupyter or pip install jupyterlab if you haven't already.
  • Double-check that your Python environment matches the version Webots uses (you can find this in Webots under Help > About Webots to avoid compatibility headaches).

Step 1: Locate Webots' Python Library Path

Webots ships with its own Python bindings, so we need to point Jupyter to their location:

  • Windows: Typically C:\Program Files\Webots\lib\controller\python
  • macOS: Look in /Applications/Webots.app/Contents/lib/controller/python
  • Linux: Usually /usr/local/webots/lib/controller/python (adjust if you installed Webots in a custom directory)

Step 2: Add Webots Path to Jupyter's Python Environment

You have two options here, depending on whether you want a temporary or permanent setup:

Option 1: Temporary Setup (per notebook session)

In the first cell of your Jupyter notebook, run these lines to append the Webots path for the current session only:

import sys
# Replace with your actual Webots Python path
webots_path = "/Applications/Webots.app/Contents/lib/controller/python"
sys.path.append(webots_path)

You'll need to run this cell every time you open the notebook.

Option 2: Permanent Setup (all Jupyter sessions)

To avoid repeating the path setup, add it to your Python environment permanently:

  1. Create a text file named webots.pth
  2. Paste the full Webots Python library path into the file (just the raw path, no quotes or extra text)
  3. Move this .pth file to your Python environment's site-packages directory:
    • Windows: C:\PythonXX\Lib\site-packages (replace XX with your Python version)
    • macOS/Linux: /usr/local/lib/pythonX.X/site-packages (or the site-packages folder of your virtual environment if you use one)

Step 3: Test the Configuration

Create a new Jupyter notebook and run this simple test to confirm everything works:

from controller import Robot

# Initialize the robot instance
robot = Robot()

# Get the simulation time step
timestep = int(robot.getBasicTimeStep())

# Run a quick test loop
while robot.step(timestep) != -1:
    print("Webots is running in Jupyter! 🎉")
    break  # Stop after one iteration to avoid infinite loop in the notebook

If you see the printed message without import or runtime errors, you're all set!

Quick Workflow Tips

  • Since Jupyter cells share the same context, you can initialize the Robot object in one cell and reuse it in subsequent cells for incremental testing.
  • If you hit import errors, double-check that your Webots path is correct and that your Python version matches what Webots supports.
  • For longer simulations, JupyterLab tends to handle long-running cells better than the classic Jupyter Notebook interface.

内容的提问来源于stack exchange,提问作者Steve Brown

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 11:44:08