Tuesday, 29 September 2020

How to Load two different Python Modules whose shared library requirements conflict if set globally

I am working on a project where I need to use two python modules together:

After following the instructions to install PyMesh from source, I was able to succesfully import pymesh with my Python 3.8 interpreter (on Ubuntu 18).

I then downloaded and installed PyRep. This initially didn't work, and gave the error:

    ~/.local/lib/python3.8/site-packages/pyrep/backend/sim.py in <module>
      1 from .simConst import *
----> 2 from ._sim_cffi import ffi, lib
      3 import numpy as np
      4 import collections
      5 

ImportError: libcoppeliaSim.so.1: cannot open shared object file: No such file or directory

The installation instructions for PyRep said this is because I need to ensure that PyRep has access to the shared libraries in my local CoppeliaSim installation, and that I should add the following lines to my .bashrc:

export COPPELIASIM_ROOT=EDIT/ME/PATH/TO/COPPELIASIM/INSTALL/DIR
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$COPPELIASIM_ROOT
export QT_QPA_PLATFORM_PLUGIN_PATH=$COPPELIASIM_ROOT

Success! I can import pyrep without issue. However, if I now import pymesh again, I get an error:

~/.local/lib/python3.8/site-packages/pymesh2-0.3-py3.8-linux-x86_64.egg/pymesh/Mesh.py in <module>
      3 import numpy as np
      4 
----> 5 import PyMesh
      6 
      7 class Mesh(object):

ImportError: /home/craig/Programs/CoppeliaSim/libtbb.so: file too short

By globally setting $LD_LIBRARY_PATH at bash login as suggested, I've caused pymesh to search for conflicting shared libraries in the Coppelia-Sim Root folder! (Looking for solutions, I found an article which condems changing $LD_LIBRARY_PATH in .bashrc for exactly this reason)

How do I resolve this dilemna? PyRep asks me to add a directory to the LD_LIBRARY_PATH, but PyMesh breaks if I do so (though I can get each to work in isolation).

Attempted Alternatives

I have learned through researching this problem that you can change where a particular shared library looks for dependencies using the patchelf command. So I tried just manually tweaking where the offending PyRep _sim_cffi library with:

patchelf --set-rpath "/home/craig/Programs/CoppeliaSim" ~/.local/lib/python3.8/site-packages/pyrep/backend/_sim_cffi.cpython-38-x86_64-linux-gnu.so

However, this just leads to transitive dependency errors one level down:

~/.local/lib/python3.8/site-packages/pyrep/backend/sim.py in <module>
      1 from .simConst import *
----> 2 from ._sim_cffi import ffi, lib
      3 import numpy as np
      4 import collections
      5 

ImportError: libQt5SerialPort.so.5: cannot open shared object file: No such file or directory


from How to Load two different Python Modules whose shared library requirements conflict if set globally

No comments:

Post a Comment