问题
Let's say we have two different Python packages from the same vendor, named with the same name -- foo
. One is installed with pip
and can be found in the /usr/lib/python/site-packages/foo
directory, the second one is a system-wide dependency which you install with e.g. apt-get
and the Python package ends up in /usr/lib/some-vendor-sdk/foo
. Local and global foo
do different things and I need them both to be importable in my source code, but I can only import one:
$ python
>>> import foo
>>> foo.__path__
/usr/lib/python2.7/site-packages/foo
Is there a way to make both packages importable in my code? It'd be fine to alias one of them somehow, I just don't know a technical way to do it. Any suggestions?
来源:https://stackoverflow.com/questions/59051935/resolve-conflicting-package-names-in-python