Ask coding questions

← Back to all posts
Importing issue with duplicate import names
StingChameleon (1)

Sorry for not providing a repl, but it shouldn't be necessary.

Here's my issue: I'm trying to use pyjwt for encoding tokens for my webapp. This library is imported via import jwt. Unfortunately, this import statement causes Replit to install the jwt library instead of pyjwt. As a result, I keep getting an error that the encode module doesn't exist (because it's trying to import it from jwt instead of pyjwt).

I've tried removing jwt from my poetry files, I had some brief success using pip to uninstall both libraries and then reinstalling pyjwt, but nothing seems to stick and now I can't even get that workaround to succeed. Bottom line: I need replit to stop installing the wrong jwt library.

Any suggestions?

InvisibleOne (2687)

try doing this:

import os
os.system('pip install pyjwt')

That should install it via pip, and if it is already installed, it should just give you a warning that the dependency is already met but continue running.

StingChameleon (1)

I'm not really having any issues installing the correct package... the issue that I'm having is that automatically installs the wrong package, as well, and that package takes precedence when importing.
I found a temporary solution in using an alternate library, but, as with most of my questions, I'd prefer to find a more straight-forward solution to the issue than working around it. In any case, thanks!