Imports incorrect modules in Python when Poetry already has correct module
AlexBlandin opened this issue · 4 comments
So some packages, such as py-ulid
, have a different name from the imported module, in this case import ulid
, or as usually done, from ulid import ULID
.
If you import with Repl.it, then the first time you run it everything works fine. If you close and open again, the next time it tries to import the module ulid
, which has a completely different interface and doesn't have a ULID
class to import, and now no longer runs as ulid
, which python attempts to resolve against rather than py-ulid
(and doesn't keep checking after the failure), doesn't have a ULID
to import.
Namely, UPM needs to either check against the existing packages that have been added, seeing if they are applicable, or it needs to check whether the packages it tried to include actually satisfy the interface of the program (even just flagging up that the ulid
package doesn't have ULID
while py-ulid
, which is already in the Poetry file, does).
This isn't really the fault of UPM, since Python is the one not checking for these when it is trying to resolve the imports, however this needs to be worked around in order to be Universal until (if ever) Python fixes this, especially for versions that do not have the fixed version should it ever happen.
Still an issue for me.
Looks like a user is having this same issue trying to use "pyjwt" instead of "jwt":
https://replit.com/talk/ask/Importing-issue-with-duplicate-import-names/132288