'Getting "Can't add new modules after the interpreter has been initialized", from ctypes.CDLL

I have built a shared library of this project:- ORB_SLAM3.

But when I try to import it in python I get the following error:-

terminate called after throwing an instance of 'std::runtime_error'
  what():  Can't add new modules after the interpreter has been initialized
Aborted (core dumped)

My code that tries to load the library.

import ctypes
import pathlib

p = pathlib.Path().absolute() / "libORB_SLAM3.so"
lib = ctypes.CDLL(p)

What am I doing wrong here please suggest.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source