Skip to content Skip to sidebar Skip to footer

Python: Two Packages With The Same Name; How Do You Specify Which Is Loaded?

I have two packages that install different packages with the same name. They are both 'packages' in that they have top-level setup.py files which specify package=['foo'] in the se

Solution 1:

Setuptools guide mentions --multi-version (-m) switch that removes package from sys.path completely. You have to use pkg_resources.require('package==version') in your code as early as possible to let it fix sys.path. This advice is what easy_install always prints when one uses -m.

But you can't have both imported at once (unless they're designed to do so using namespace packages).

Solution 2:

I think the best way to workaround, would be to change the name of the toplevel directory, unless other packages depend on that package.

You can do this by altering the setup.py or just change the name folder in site-packages directly. The egg is just meta data.

As far as setting sys.path, it's better to use the site module, by creating a .pth file. When instantiated, any paths located in that file will be added to the "head" of the python path.

Are these two packages different and the naming is a coincidence, or are they simply branches of the same?

Post a Comment for "Python: Two Packages With The Same Name; How Do You Specify Which Is Loaded?"