How to handle python packages with conflicting names?
Asked Answered
M

2

21

I'm using two python packages that have the same name.

Is there a canonical or pythonic way to handle installing two packages with conflicting names? So far, I've only occasionally needed one of the packages during development/building, so I've been using a separate virtualenv to deal with the conflict, but it makes the build step more complex and I wonder if there isn't a better way to handle it.

Mima answered 17/12, 2014 at 18:13 Comment(1)
Virtualenv is the best way, i think.Someway
V
12

You could use the --target option for pip and install to an alternate location:

pip install --target=/tmp/test/lib/python3.6/site-packages/alt_alembic alembic

Then when you import in python, do the first as usual and for the alt do an import from that namespace like this:

import alembic  # alembic.io version
from alt_alembic import alembic as alt_alembic  # pip version

Then when you're making calls to that one you can call alt_alembic.function() and to the one that isn't in PyPi, alembic.function() My target path has /tmp/test as I was using a virtual env. You would need to replace that path with the correct one for your python installation.

Vitrescent answered 16/2, 2017 at 13:14 Comment(0)
B
-2

how about absolute and relative imports.

https://docs.python.org/2/whatsnew/2.5.html#pep-328-absolute-and-relative-imports

Bode answered 18/12, 2014 at 6:53 Comment(2)
Using relative imports would handle internal module or sub-package conflicts with other top-level modules and packages, but it won't help when two top level packages are named the same.Mima
then we should use virtualenvBode

© 2022 - 2024 — McMap. All rights reserved.