Error in macOS Catalina

Typically: "How do I... ", "How can I... " questions
Post Reply
darn
Posts: 12
Joined: 10 Apr 2020, 18:48

Error in macOS Catalina

Post by darn »

Hello everyone,

I am trying to run CoppeliaSim with a script from Python using the b0RemoteApiServer. I run the add-on on the simulator
and I follow all the steps in the forums but I keep getting this error:

File "/Users/dani/devel/coppeliasim_api_tests/coppeliasimapi.py", line 3, in <module>
import b0RemoteApi
File "/Users/dani/devel/coppeliasim_api_tests/b0RemoteApi.py", line 6, in <module>
import b0
File "/Users/dani/devel/coppeliasim_api_tests/b0.py", line 21, in <module>
raise RuntimeError('%sb0%s not found' % (prefix, suffix))
RuntimeError: libb0.dylib not found

I am using macOS Catalina version 10.15.4.
Any idea of what could be happening?

Thank you in advance!

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Error in macOS Catalina

Post by coppelia »

hello,

can you try to start your remote API client from within CoppeliaSim's bundle folder coppeliaSim.app/Contents/MacOS/ and tell us if you still have that problem?

Cheers

darn
Posts: 12
Joined: 10 Apr 2020, 18:48

Re: Error in macOS Catalina

Post by darn »

Hello,

Thank you very much for your answer.
I have tried to run the script from that folder and I get the same error.
Do you need me to provide any other information?

Thank you in advance.

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: Error in macOS Catalina

Post by fferri »

The routine for finding the b0 library (at beginning of file b0.py) doesn't seem correct. Additionally, there is another issue on macOS that prevents loading the library even when it is reached by the correct path.

I gave it a shot at rewriting the routine.
Can you try replacing the code in b0.py:

Code: Select all

#python
libb0 = None
prefix, suffix = 'lib', '.so'
if platform.system() in ('cli', 'Windows'):
    prefix, suffix = '', '.dll'
if platform.system() in ('Darwin', ):
    suffix = '.dylib'
for path in ('.', 'build', '../../build'):
    fullpath = os.path.join(os.path.dirname(__file__), path)
    if not os.path.isdir(fullpath): continue
    libb0_fullpath = os.path.join(fullpath, '%sb0%s' % (prefix, suffix))
    if os.path.exists(libb0_fullpath):
        libb0 = ct.CDLL(libb0_fullpath)
        break
if libb0 is None:
    raise RuntimeError('%sb0%s not found' % (prefix, suffix))
with this:

Code: Select all

#python
verbose = bool(os.environ.get('VERBOSE', False))

# determine coppeliaSim root directory from env var or relative to the standard
# location of this script:
coppeliasim_dir = None
for maybe in (
    os.environ.get('COPPELIASIM_ROOT_DIR'),
    os.environ.get('VREP_ROOT'),
    os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..')
):
    if maybe and os.path.isdir(maybe) and os.path.isdir(os.path.join(maybe, 'helpFiles')):
        coppeliasim_dir = os.path.normpath(maybe)
        break
if coppeliasim_dir is None:
    print('CoppeliaSim directory not found')
    sys.exit(1)
else:
    if verbose:
        print('Found CoppeliaSim directory at %s' % coppeliasim_dir)

# platform specific details for finding b0 library:
if platform.system() in ('cli', 'Windows'):
    prefix, suffix = '', '.dll'
    libpath_var, libpath = 'PATH', coppeliasim_dir
elif platform.system() in ('Darwin', ):
    prefix, suffix = 'lib', '.dylib'
    libpath_var, libpath = 'DYLD_LIBRARY_PATH', os.path.join(coppeliasim_dir, 'coppeliaSim.app/Contents/Frameworks')
else: # Linux
    prefix, suffix = 'lib', '.so'
    libpath_var, libpath = 'LD_LIBRARY_PATH', coppeliasim_dir

libb0_name = prefix + 'b0' + suffix
try:
    lp = os.environ.get(libpath_var)
    if verbose:
        print('Trying to load {libb0_name}... ({libpath_var} is {lp})'.format(**locals()))
    libb0 = ct.CDLL(libb0_name)
except OSError:
    # if libb0 fails to load, try to relaunch python specifying the environment variable
    # that will (hopefully) make possible to load it (if not already done):
    if os.pathsep + libpath_var + os.pathsep in os.pathsep + os.environ.get(libpath_var, '') + os.pathsep:
        raise RuntimeError('%s not found' % libb0_name)
    os.environ[libpath_var] = libpath + os.pathsep + os.environ.get(libpath_var, '')
    import subprocess
    if verbose:
        print('Relaunching {sys.executable} with args {sys.argv} and {libpath_var}={libpath}...'.format(**locals()))
    subprocess.call([sys.executable] + sys.argv, env=os.environ)
    exit(0)

if verbose:
    print('libb0:', libb0)
and see if it works for you?

Note that if you don't run this code from the CoppeliaSim/programming/b0remoteApiBindings/python directory, you need to set the COPPELIASIM_ROOT_DIR variable (i.e. export COPPELIASIM_ROOT_DIR=/Applications/CoppeliaSim_Edu_V4_0_0_rev4_Mac adjusting for the correct path on your system) before running the python code in the same shell (or you may put that command in your ~/.bashrc for convenience so that you don't have to type it every time).

darn
Posts: 12
Joined: 10 Apr 2020, 18:48

Re: Error in macOS Catalina

Post by darn »

That solved the problem. Thank you very much for your help.

Just want to point out another problem I had. In macOS Catalina you have to disable the System Integrity Protection or it won't let you set the global variables DYLD_LIBRARY_PATH and LD_LIBRARY_PATH. Here you have a link that explain the process for enable or disable it:

https://developer.apple.com/library/arc ... ction.html

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: Error in macOS Catalina

Post by fferri »

Do you mean the above fix doesn't work for you with SIP enabled?

On my machine SIP is enabled, but the above fix works.

EDIT: I think I found the reason, which is my python interpreter being not the one installed with the system in /usr/bin/python which is protected by SIP, but a newer Python 3 version at /usr/local/bin/python3 installed via homebrew, hence why it is not affected by SIP.

Also note that LD_LIBRARY_PATH is a variable used by Linux's dynamic linker only. DYLD_LIBRARY_PATH is the corresponding variable used by macOS' dynamic linker.

Post Reply