Skip to content

Link Pycharm and Webots

JinkaiQiu edited this page Aug 16, 2022 · 2 revisions

Use python external controller for Webots in Pycharm Setups

Navigate to Pycharm Section in Official Instruction

You need to (follow that section):

  1. Add Content Root under Project -> Project Structure

  2. Add Environmental Variable under Run -> Run/Debug Configuration

  3. Important: Add Windows Environmental Variable (follow this and Official List)

    WEBOTS_HOME = C:\Program Files\Webots (Or any Installation Location)

    Path = Create new one if not exist or add %WEBOTS_HOME%\lib\controller by double clicking orginal Path Variable and click New

    Path (only if Python < 3.8) = add %WEBOTS_HOME%\msys64\mingw64\bin and %WEBOTS_HOME%\msys64\mingw64\bin\cpp

    PYTHONPATH = Create new one if not exist or add ${WEBOTS_HOME}\lib\controller\python3X (Replace X with python version (ie. python39))

    PYTHONIOENCODING = UTF-8

    Important: Restart computer to take effect, won't work if not restarted

  4. Open Webots and Navigate to File -> Open Sample World or open desired World (the one declared in the .py file)

  5. Toggle Controller Option to <extern> by clicking controller (in one of the nodes in the Window on the left with many circles) -> select <extern>

  6. Under the same tab, toggle Supervisor to TRUE

  7. Click Reset Similation (Ctrl+Shift+T) and Run

  8. Run the .Py file (eg. Webots_example_Run.py)

  9. Done :)

Common Errors

Pycharm raises KeyError: 'WEBOTS_HOME'

Solution:

  • Check settings in Pycharm
  • Check Environmental Variables in Windows settings; Remember to restart computer to take effect

Pycharm raises ImportError: the Webots robot _____ could not be found

Solution:

  • Restart simulation and Restart Webots software
  • Restart computer