When installing packages from PyPI, you have to use the name of the project, which is different from the name of the top-level packages which you will actually import. A clear example is pyserial and serial, which get installed using:
pip install serial
pip install pyserial
But both are used with something like:
import serial
If you explore the site-packages
folder, you see that the contents are the combination of both packages, and, of course, the files get overwritten by the latest to be installed, giving unpredictable results.
Is there a way of avoiding this kind of name clashes when installing packages in Python? Imagine you would like to use both pyserial and serial, how would you then install them?
zope
). For your own code you can somehow get around it, for example by usingimportlib
directly. But if you have dependencies A and B, where A wants to importserial
from the projectserial
and B wants to importserial
from the projectpyserial
, then it's way trickier. Maybe somehow by further hacking intoimportlib
there is a way to detect which module is trying to importserial
and then serve the right one... – Liturgy