fix for vrep.py

Report crashes, strange behaviour, or apparent bugs
Post Reply
fabien
Posts: 4
Joined: 10 Jun 2013, 11:57

fix for vrep.py

Post by fabien »

Hi,

In 3.2.3, on Mac OS X, the `vrep.py` file from `remoteApiBindings/python/python` contains these lines:

Code: Select all

from ctypes import *

libsimx = None
try:
    if platform.system() =='Windows':
        libsimx = CDLL("./remoteApi.dll")
    elif platform.system() == 'Darwin':
        libsimx = CDLL(os.path.abspath(os.path.join(__file__, '../remoteApi.dylib'), ))
    else:
        libsimx = CDLL("./remoteApi.so")
except:
Yet, on the Linux distribution (64 bits), the same lines are:

Code: Select all

import ctypes as ct

libsimx = None
try:
    if platform.system() =='cli':
        libsimx = ct.CDLL("./remoteApi.dll")
    elif platform.system() =='Windows':
        libsimx = ct.CDLL("./remoteApi.dll")
    elif platform.system() == 'Darwin':
        libsimx = ct.CDLL("./remoteApi.dylib")
    else:
        libsimx = ct.CDLL("./remoteApi.so")
except:
This seems weird that the OS X and Mac distribution have two slightly different versions for this file. Anyway, on Linux, this generates an error when remoteApi.so and vrep.py are moved to the `site-package/` directory where python packages are typically installed (or any directory besides the current one). The correct version would be, as far as Linux and OS X are concerned, and if I am not mistaken:

Code: Select all

import os # missing from Linux version.
import ctypes as ct # better than from ctypes import *, which is typically frown upon. (impacts many other lines in the file)

libsimx = None
try:
    if platform.system() in ('cli', 'Windows'): # more compact
        libsimx = ct.CDLL("./remoteApi.dll")
    elif platform.system() == 'Darwin':
        libsimx = ct.CDLL(os.path.abspath(os.path.join(__file__, '../remoteApi.dylib')))
    else:
        libsimx = ct.CDLL(os.path.abspath(os.path.join(__file__, "../remoteApi.so")))
except Exception as e: 
    print(e) # prints informative message, such as:
             # "/home/fbenurea/.pyenv/versions/2.7.6/lib/python2.7/site-packages/remoteApi.so: cannot open shared object file: No such file or directory" 
             # or 
             # "name 'os' is not defined"
             # which help diagnose the problem
The Windows and "cli" line should probably be modified as well in the same manner, but I have no experience with those platforms.

Cheers,
Fabien

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

Re: fix for vrep.py

Post by coppelia »

Hello Fabien,

thanks for the information. The file should be exactly the same on all 3 platforms.
As far as I can remember, there used to be many compatibility problems in the past, depending on the OS and how people install things, so we resorted to current solution. It is also problematic to change things now, where other applications (that we are not in control of) are relying on current settings.

Cheers

Post Reply