pythoncomputer-visionpython-import.so

Can't import .so file due to permissions missing: failed to map segment from shared object


I'm trying to run a custom project that uses large parts of the SiamMask project. When the code is ran, one of the many imports is this one:

from . import region

located in an __init__.py file. It is trying to import a .so file called region.cpython-36m-x86_64-linux-gnu.so which is located in the same directory as the __init__.py file.

However, when I run the code, I get the following error:

ImportError: /scratch/[hidden]/project/libs/siamMask/utils/pyvotkit/region.cpython-36m-x86_64-linux-gnu.so: failed to map segment from shared object: Operation not permitted

I'm pretty confident that this error is caused due to the following fact. The scratch disk I'm working on, which is mounted to the GPU server, doesn't have direct 'execute' permissions for Python related things. (There's nothing I can change about this) This is also the reason why the Python virtual environment I'm working on is located on a different drive (where the system has direct execute permissions on everything that is Python related).

My question however is, how can I import this .so file in a different way that wouldn't interfere with the above fact? Could I transfer the file to the other drive and somehow import it from there via that __init__ file?

Thank you in advance!


Solution

  • I was able to fix this issue in the following way:

    I moved the region.cpython-36m-x86_64-linux-gnu.so file to the other drive where Python can execute. I then used the following code in the __init__ file:

    import sys
    
    sys.path.append('/path/to/.sofile')
    
    import region