0

Assume module(A) and another third-party module(B) depend on the same name but different version module(C), and module B has updated sys.path to make sure required version module C is imported(not a good practice though). Conflict happens if:

# A.py
import C # this imports C v0.1
C.do_something()
import B
B.do_something() # crash because B is not compatible with C v0.1

# B.py
def do_something():
  sys.path.insert(0, "/path/to/C_v0.2/")
  import C # this will not load C v0.2 because C v0.1 is already imported
  C.do_something()  # this will not work as expected

What can I do to avoid this conflict if I can't update module B's code?

konchy
  • 573
  • 5
  • 16

0 Answers0