Search code examples
webots

Running an external python controller from console


While trying to figure out how to integrate the gym interface, I'm trying to get an extern robot python controller running from console. I have follwed the offical guide and my (macOS) env vars set accordingly.

When I try to run the controller by typing:

python (path to controller.py)

I get the following message:

ModuleNotFoundError: No module named 'controller'

Can someone give me a tip how to figure this out?

==========

Update: As asked in the comments, here's my output

environ({'TERM_PROGRAM': 'Hyper', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'TMPDIR': '/var/folders/g1/sqrwrg2d5mn9d48z24mng2280000gn/T/', 'CONDA_SHLVL': '1', 'CONDA_PROMPT_MODIFIER': '(base) ', 'TERM_PROGRAM_VERSION': '3.0.2', 'WEBOTS_HOME': '/Applications/Webots', 'PYTHONIOENCODING': 'UTF-8', 'USER': '[user]', 'CONDA_EXE': '/Users/[user]/anaconda3/bin/conda', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0', '_CE_CONDA': '', 'PATH': '/Users/[user]/anaconda3/bin:/Users/[user]/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands', 'CONDA_PREFIX': '/Users/[user]/anaconda3', 'PWD': '/Users/[user]', 'LANG': 'en_US.UTF-8', 'XPC_FLAGS': '0x0', '_CE_M': '', 'XPC_SERVICE_NAME': '0', 'SHLVL': '1', 'HOME': '/Users/[user]', 'DYLD_LIBRARY_PATH': '/Applications/Webots/lib/controller:', 'PYTHONPATH': '/Applications/Webots/lib/controller/python3X:', 'CONDA_PYTHON_EXE': '/Users/[user]/anaconda3/bin/python', 'LOGNAME': '[user]', 'CONDA_DEFAULT_ENV': 'base', 'COLORTERM': 'truecolor', '_': '/Users/[user]/anaconda3/bin/python'})

Python version

print(sys.version)
3.7.3 (default, Mar 27 2019, 16:54:48) 
[Clang 4.0.1 (tags/RELEASE_401/final)]

==========

Update 2: Segmentation fault: 11 error

Here is my crash report / macOS console output when trying to run "python [extern robot controller].py"

Log from console app

Full Crash Report:

Process:               python3.7 [6940]
Path:                  /Users/USER/*/python3.7
Identifier:            python3.7
Version:               ???
Code Type:             X86-64 (Native)
Parent Process:        bash [5209]
Responsible:           python3.7 [6940]
User ID:               501

Date/Time:             2020-01-22 11:34:43.349 +0100
OS Version:            Mac OS X 10.14.6 (18G2022)
Report Version:        12

Time Awake Since Boot: 33000 seconds
Time Since Wake:       6800 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000008
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [6940]

VM Regions Near 0x8:
--> 
    __TEXT                 0000000104cd3000-0000000104fa4000 [ 2884K] r-x/rwx SM=COW  /Users/USER/*/*.7

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   org.python.python               0x00000001052b4bbc PyTuple_New + 252
1   org.python.python               0x00000001052b76ba PyType_Ready + 218
2   org.python.python               0x00000001052b767c PyType_Ready + 156
3   _controller.so                  0x000000010515b227 SwigPyPacked_TypeOnce() + 87
4   _controller.so                  0x0000000105112a1f SwigPyPacked_type() + 47
5   _controller.so                  0x0000000105110b02 PyInit__controller + 34
6   python                          0x0000000104e6ca6d _PyImport_LoadDynamicModuleWithSpec + 557
7   python                          0x0000000104e6be83 _imp_create_dynamic + 243
8   python                          0x0000000104d0182f _PyMethodDef_RawFastCallDict + 255
9   python                          0x0000000104d02f3d PyCFunction_Call + 61
10  python                          0x0000000104e3cb50 _PyEval_EvalFrameDefault + 46624
11  python                          0x0000000104e302ee _PyEval_EvalCodeWithName + 414
12  python                          0x0000000104d02623 _PyFunction_FastCallKeywords + 195
13  python                          0x0000000104e3ec07 call_function + 183
14  python                          0x0000000104e3ba36 _PyEval_EvalFrameDefault + 42246
15  python                          0x0000000104d01ef5 function_code_fastcall + 117
16  python                          0x0000000104e3ec07 call_function + 183
17  python                          0x0000000104e3b9a0 _PyEval_EvalFrameDefault + 42096
18  python                          0x0000000104d01ef5 function_code_fastcall + 117
19  python                          0x0000000104e3ec07 call_function + 183
20  python                          0x0000000104e3c978 _PyEval_EvalFrameDefault + 46152
21  python                          0x0000000104d01ef5 function_code_fastcall + 117
22  python                          0x0000000104e3ec07 call_function + 183
23  python                          0x0000000104e3c978 _PyEval_EvalFrameDefault + 46152
24  python                          0x0000000104d01ef5 function_code_fastcall + 117
25  python                          0x0000000104e3ec07 call_function + 183
26  python                          0x0000000104e3c978 _PyEval_EvalFrameDefault + 46152
27  python                          0x0000000104d01ef5 function_code_fastcall + 117
28  python                          0x0000000104d04598 object_vacall + 248
29  python                          0x0000000104d04793 _PyObject_CallMethodIdObjArgs + 243
30  python                          0x0000000104e655e8 PyImport_ImportModuleLevelObject + 3640
31  python                          0x0000000104e3a7be _PyEval_EvalFrameDefault + 37518
32  python                          0x0000000104e302ee _PyEval_EvalCodeWithName + 414
33  python                          0x0000000104e2ad1b builtin_exec + 347
34  python                          0x0000000104d0182f _PyMethodDef_RawFastCallDict + 255
35  python                          0x0000000104d02f3d PyCFunction_Call + 61
36  python                          0x0000000104e3cb50 _PyEval_EvalFrameDefault + 46624
37  python                          0x0000000104e302ee _PyEval_EvalCodeWithName + 414
38  python                          0x0000000104d02623 _PyFunction_FastCallKeywords + 195
39  python                          0x0000000104e3ec07 call_function + 183
40  python                          0x0000000104e3ba36 _PyEval_EvalFrameDefault + 42246
41  python                          0x0000000104d01ef5 function_code_fastcall + 117
42  python                          0x0000000104e3ec07 call_function + 183
43  python                          0x0000000104e3b9a0 _PyEval_EvalFrameDefault + 42096
44  python                          0x0000000104d01ef5 function_code_fastcall + 117
45  python                          0x0000000104e3ec07 call_function + 183
46  python                          0x0000000104e3c978 _PyEval_EvalFrameDefault + 46152
47  python                          0x0000000104d01ef5 function_code_fastcall + 117
48  python                          0x0000000104e3ec07 call_function + 183
49  python                          0x0000000104e3c978 _PyEval_EvalFrameDefault + 46152
50  python                          0x0000000104d01ef5 function_code_fastcall + 117
51  python                          0x0000000104d04598 object_vacall + 248
52  python                          0x0000000104d04793 _PyObject_CallMethodIdObjArgs + 243
53  python                          0x0000000104e655e8 PyImport_ImportModuleLevelObject + 3640
54  python                          0x0000000104e3a7be _PyEval_EvalFrameDefault + 37518
55  python                          0x0000000104e302ee _PyEval_EvalCodeWithName + 414
56  python                          0x0000000104e93b30 PyRun_FileExFlags + 256
57  python                          0x0000000104e92fa7 PyRun_SimpleFileExFlags + 391
58  python                          0x0000000104ec0c03 pymain_main + 9635
59  python                          0x0000000104cd4b4d main + 125
60  libdyld.dylib                   0x00007fff605f73d5 start + 1

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x0000000000000000  rcx: 0x00007ff0981d0070  rdx: 0x0000000000000001
  rdi: 0x00007ffeeaf29720  rsi: 0x00000000000000b0  rbp: 0x00007ffeeaf297b0  rsp: 0x00007ffeeaf297a0
   r8: 0x000000000004896a   r9: 0xffffffff00000000  r10: 0x00007fff965bdf20  r11: 0x0000000000007268
  r12: 0x00007ff0980fe1f0  r13: 0x00007ff0981b6cb0  r14: 0x00007ff0981d0090  r15: 0x00007ff0981b87b0
  rip: 0x00000001052b4bbc  rfl: 0x0000000000010286  cr2: 0x0000000000000008

Logical CPU:     0
Error Code:      0x00000004
Trap Number:     14


Binary Images:
       0x104cd3000 -        0x104fa3ff3 +python (0) <2B301754-257D-3DA4-AE87-D8E7130D0FDD> /Users/USER/*/python
       0x10510b000 -        0x10510cffb +_heapq.cpython-37m-darwin.so (0) <D906D624-3DB4-38D7-BBA7-C5A190E6004D> /Users/USER/*/_heapq.cpython-37m-darwin.so
       0x105110000 -        0x105174ffb +_controller.so (0) <463868E2-5338-37BE-9ACD-C7724ED991D2> /Applications/Webots.app/lib/controller/python37/_controller.so
       0x10519b000 -        0x1051f7ff3 +libController.dylib (0) <A4DC5732-6D61-39C2-BD67-50B59BAF0811> /Applications/Webots.app/lib/controller/libController.dylib
       0x105209000 -        0x10521fff3 +libCppController.dylib (0) <9501D468-20A7-3C3D-869A-0346F0011AAB> /Applications/Webots.app/lib/controller/libCppController.dylib
       0x10524d000 -        0x105426fff +org.python.python (3.7.4, [c] 2001-2019 Python Software Foundation. - 3.7.4) <AC1AEBEB-FF5A-32AD-BAE0-C6A0BCA86B84> /Library/Frameworks/Python.framework/Versions/3.7/Python
       0x10be10000 -        0x10be7a70f  dyld (655.1.1) <B3D9DDCB-5AA7-3674-9608-16B5AA4AA494> /usr/lib/dyld
    0x7fff34636000 -     0x7fff34a7bfef  com.apple.CoreFoundation (6.9 - 1575.23) <596DBC2A-60E3-3A73-AA5F-7A1806CF3204> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
    0x7fff5d19b000 -     0x7fff5d19cffb  libDiagnosticMessagesClient.dylib (107) <A14D0819-0970-34CD-8680-80E4D7FE8C2C> /usr/lib/libDiagnosticMessagesClient.dylib
    0x7fff5d5db000 -     0x7fff5d5dcffb  libSystem.B.dylib (1252.250.1) <9AA73992-2087-34AF-803E-2D727104B989> /usr/lib/libSystem.B.dylib
    0x7fff5d820000 -     0x7fff5d873ff7  libc++.1.dylib (400.9.4) <9A60A190-6C34-339F-BB3D-AACE942009A4> /usr/lib/libc++.1.dylib
    0x7fff5d874000 -     0x7fff5d889ff7  libc++abi.dylib (400.17) <38C09CED-9090-3719-90F3-04A2749F5428> /usr/lib/libc++abi.dylib
    0x7fff5e2d0000 -     0x7fff5e531ffb  libicucore.A.dylib (62141.0.1) <A0D63918-76E9-3C1B-B255-46F4C1DA7FE8> /usr/lib/libicucore.A.dylib
    0x7fff5ee14000 -     0x7fff5f599fdf  libobjc.A.dylib (756.2) <7C312627-43CB-3234-9324-4DEA92D59F50> /usr/lib/libobjc.A.dylib
    0x7fff5fc84000 -     0x7fff5fc96ff7  libz.1.dylib (70.200.4) <B048FC1F-058F-3A08-A1FE-81D5308CB3E6> /usr/lib/libz.1.dylib
    0x7fff6047a000 -     0x7fff6047eff3  libcache.dylib (81) <1987D1E1-DB11-3291-B12A-EBD55848E02D> /usr/lib/system/libcache.dylib
    0x7fff6047f000 -     0x7fff60489ff3  libcommonCrypto.dylib (60118.250.2) <1765BB6E-6784-3653-B16B-CB839721DC9A> /usr/lib/system/libcommonCrypto.dylib
    0x7fff6048a000 -     0x7fff60491ff7  libcompiler_rt.dylib (63.4) <5212BA7B-B7EA-37B4-AF6E-AC4F507EDFB8> /usr/lib/system/libcompiler_rt.dylib
    0x7fff60492000 -     0x7fff6049bff7  libcopyfile.dylib (146.250.1) <98CD00CD-9B91-3B5C-A9DB-842638050FA8> /usr/lib/system/libcopyfile.dylib
    0x7fff6049c000 -     0x7fff60520fc3  libcorecrypto.dylib (602.260.2) <01464D24-570C-3B83-9D18-467769E0FCDD> /usr/lib/system/libcorecrypto.dylib
    0x7fff605a7000 -     0x7fff605e0ff7  libdispatch.dylib (1008.270.1) <97273678-E94C-3C8C-89F6-2E2020F4B43B> /usr/lib/system/libdispatch.dylib
    0x7fff605e1000 -     0x7fff6060dff7  libdyld.dylib (655.1.1) <002418CC-AD11-3D10-865B-015591D24E6C> /usr/lib/system/libdyld.dylib
    0x7fff6060e000 -     0x7fff6060effb  libkeymgr.dylib (30) <0D0F9CA2-8D5A-3273-8723-59987B5827F2> /usr/lib/system/libkeymgr.dylib
    0x7fff6061c000 -     0x7fff6061cff7  liblaunch.dylib (1336.261.2) <2B07E27E-D404-3E98-9D28-BCA641E5C479> /usr/lib/system/liblaunch.dylib
    0x7fff6061d000 -     0x7fff60622fff  libmacho.dylib (927.0.3) <A377D608-77AB-3F6E-90F0-B4F251A5C12F> /usr/lib/system/libmacho.dylib
    0x7fff60623000 -     0x7fff60625ff7  libquarantine.dylib (86.270.1) <50A89DAB-7E34-3347-9AD5-68957B27EFD2> /usr/lib/system/libquarantine.dylib
    0x7fff60626000 -     0x7fff60627ff7  libremovefile.dylib (45.200.2) <9FBEB2FF-EEBE-31BC-BCFC-C71F8D0E99B6> /usr/lib/system/libremovefile.dylib
    0x7fff60628000 -     0x7fff6063fff3  libsystem_asl.dylib (356.200.4) <A62A7249-38B8-33FA-9875-F1852590796C> /usr/lib/system/libsystem_asl.dylib
    0x7fff60640000 -     0x7fff60640ff7  libsystem_blocks.dylib (73) <A453E8EE-860D-3CED-B5DC-BE54E9DB4348> /usr/lib/system/libsystem_blocks.dylib
    0x7fff60641000 -     0x7fff606c8fff  libsystem_c.dylib (1272.250.1) <7EDACF78-2FA3-35B8-B051-D70475A35117> /usr/lib/system/libsystem_c.dylib
    0x7fff606c9000 -     0x7fff606ccffb  libsystem_configuration.dylib (963.270.3) <2B4A836D-68A4-33E6-8D48-CD4486B03387> /usr/lib/system/libsystem_configuration.dylib
    0x7fff606cd000 -     0x7fff606d0ff7  libsystem_coreservices.dylib (66) <719F75A4-74C5-3BA6-A09E-0C5A3E5889D7> /usr/lib/system/libsystem_coreservices.dylib
    0x7fff606d1000 -     0x7fff606d7fff  libsystem_darwin.dylib (1272.250.1) <EC9B39A5-9592-3577-8997-7DC721D20D8C> /usr/lib/system/libsystem_darwin.dylib
    0x7fff606d8000 -     0x7fff606deffb  libsystem_dnssd.dylib (878.270.3) <97EEE658-D935-33C8-B56E-0F41EA7F6B43> /usr/lib/system/libsystem_dnssd.dylib
    0x7fff606df000 -     0x7fff6072affb  libsystem_info.dylib (517.200.9) <D09D5AE0-2FDC-3A6D-93EC-729F931B1457> /usr/lib/system/libsystem_info.dylib
    0x7fff6072b000 -     0x7fff60753ff7  libsystem_kernel.dylib (4903.278.19) <2C2536E7-EA3B-32B5-AFC6-B1139A5046FD> /usr/lib/system/libsystem_kernel.dylib
    0x7fff60754000 -     0x7fff6079fff7  libsystem_m.dylib (3158.200.7) <F19B6DB7-014F-3820-831F-389CCDA06EF6> /usr/lib/system/libsystem_m.dylib
    0x7fff607a0000 -     0x7fff607cafff  libsystem_malloc.dylib (166.270.1) <011F3AD0-8E6A-3A89-AE64-6E5F6840F30A> /usr/lib/system/libsystem_malloc.dylib
    0x7fff607cb000 -     0x7fff607d5ff7  libsystem_networkextension.dylib (767.250.2) <FF06F13A-AEFE-3A27-A073-910EF78AEA36> /usr/lib/system/libsystem_networkextension.dylib
    0x7fff607d6000 -     0x7fff607ddfff  libsystem_notify.dylib (172.200.21) <145B5CFC-CF73-33CE-BD3D-E8DDE268FFDE> /usr/lib/system/libsystem_notify.dylib
    0x7fff607de000 -     0x7fff607e7fef  libsystem_platform.dylib (177.270.1) <9D1FE5E4-EB7D-3B3F-A8D1-A96D9CF1348C> /usr/lib/system/libsystem_platform.dylib
    0x7fff607e8000 -     0x7fff607f2ff7  libsystem_pthread.dylib (330.250.2) <2D5C08FF-484F-3D59-9132-CE1DCB3F76D7> /usr/lib/system/libsystem_pthread.dylib
    0x7fff607f3000 -     0x7fff607f6ff7  libsystem_sandbox.dylib (851.270.1) <9494594B-5199-3186-82AB-5FF8BED6EE16> /usr/lib/system/libsystem_sandbox.dylib
    0x7fff607f7000 -     0x7fff607f9ff3  libsystem_secinit.dylib (30.260.2) <EF1EA47B-7B22-35E8-BD9B-F7003DCB96AE> /usr/lib/system/libsystem_secinit.dylib
    0x7fff607fa000 -     0x7fff60801ff3  libsystem_symptoms.dylib (820.267.1) <03F1C2DD-0F5A-3D9D-88F6-B26C0F94EB52> /usr/lib/system/libsystem_symptoms.dylib
    0x7fff60802000 -     0x7fff60817ff7  libsystem_trace.dylib (906.260.2) <EA74D04D-5ECA-3689-9084-48E4D32C859A> /usr/lib/system/libsystem_trace.dylib
    0x7fff60819000 -     0x7fff6081effb  libunwind.dylib (35.4) <24A97A67-F017-3CFC-B0D0-6BD0224B1336> /usr/lib/system/libunwind.dylib
    0x7fff6081f000 -     0x7fff6084efff  libxpc.dylib (1336.261.2) <7DEE2300-6D8E-3C00-9C63-E3E80D56B0C4> /usr/lib/system/libxpc.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 105089
    thread_create: 0
    thread_set_state: 33

VM Region Summary:
ReadOnly portion of Libraries: Total=248.2M resident=0K(0%) swapped_out_or_unallocated=248.2M(100%)
Writable regions: Total=427.5M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=427.5M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                    8K        1 
MALLOC                            75.1M       16 
MALLOC guard page                   24K        5 
MALLOC_MEDIUM (reserved)         336.0M        3         reserved VM address space (unallocated)
STACK GUARD                          4K        1 
Stack                             16.0M        1 
__DATA                            4808K       51 
__LINKEDIT                       224.3M        8 
__TEXT                            23.9M       48 
__UNICODE                          564K        1 
shared memory                        8K        2 
===========                     =======  ======= 
TOTAL                            680.6M      137 
TOTAL, minus reserved VM space   344.6M      137 

===========

Update 3: Issue resolved !

It's working now! Thanks for your help, David & Fabien ! After doing the above modifications and having the script still crashing, I tried running with python37 instead of python.

Even though my virtual env (anaconda) should also use 3.7 (running python --version yields the same as python3.7 --version), I found out that when running the external controller script with python3.7 works. It seems like Webots is not playing well with virtual envs for the moment.

(base) mac:$ python3.7 --version
Python 3.7.4
(base) mac:$ python --version
Python 3.7.4
(base) mac:$ which python3.7
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
(base) mac:$ which python
/Users/[user]/anaconda3/bin/python

Solution

  • Webots is unfortunately quite sensitive to which Python version is used. You probably didn't installed Python as explained here (From the official installer).

    A correct installation should lead to this result:

    enter image description here

    Please do not use Python from brew or embedded in another app (PyCharm, etc).