failed import of passlib in Jetbrains PyCharm

Skip to first unread message

Jul 16, 2015, 3:28:16 AM7/16/15
Hey Folks, 
I wonder if you could help me out with a strange problem with passlib in pycharm. 

I recently installed passlib with pip and verified successful installation with python on the command line. I can successfully call functionality of the sha256_crypt class, once I have imported it with the regular import statement:
from passlib.hash import sha256_crypt

Writing the same import in pycharm, I can't get the IDE to acknowledge the existence of the sha256_crypt class. I tried all the pycharm fixes I know of, trashing caches and refreshing project interpreters but nothing fixed it. After some messing around, I tried 

from passlib.handlers.sha2_crypt import sha256_crypt

and hey-presto things are working. 

I can't find anything else about this problem online. Could someone let me know if this has been reported elsewhere? or why it's happening?

thanks a bundle :)

Eli Collins

Jul 20, 2015, 1:47:52 PM7/20/15


The problem is that passlib.hash does some lazy-importing tricks in order to load the hash classes on-demand instead of all at once (there's a lot of them, and most people only need one or two). As you found, they're actually stored over in passlib.handlers, though that's kindof an internal detail :)

This lazy-importing wouldn't normally be a problem, but PyCharm's autocomplete seems to rely on source inspection rather than examining live objects... which means it falls down when the contents of a module aren't explicitly listed.

I use PyCharm myself, and I've tried tweaking how passlib.hash does things, but so far haven't found a way to trick PyCharm. This thread ( seems to indicate this is a known issue w/ PyCharm, but it's from 2010, and I don't think anything has been done since.

If PyCharm ever adds a way for source to indicate that it's safe to live-inspect a module (e.g. by looking for some special marker comment in the source such as # -*- live-inspection-safe -*-), I'll be happy to add the flag to passlib. Heck, I'd love it for a number of other libraries where I'm using lazy importing.  Until then, this may be the state of things :(

- Eli

Reply all
Reply to author
0 new messages