Repository: pyinstaller/pyinstaller

Issue:
Import hook for passlib (password hashing library)
**Original date**: 2012/12/20
**Original reporter**: *psychosaxophone AND gmail DOT  COOM *

I'm using passlib for password authentication. However, pyinstaller doesn't include passlib when compiling, possibly because of multiple warnings. If, however, I copy the entire passlib directory from C:\python27\Lib\site-packages, the compiled program runs fine.

I know the FAQ says to try solving the warnings, but I really have no idea how to do so. I've included the warn*.txt file generated by pyinstaller.

PyInstaller is not bundling the passlib handlers: `passlib.handlers.*`



Discussion:
**Original date**: 2013/02/07
**Original reporter**: _anonymous_

I am having this same issue!

**Original date**: 2013/02/07
**Original reporter**: *darktien AND gmail DOT  COOM *

I think this is a problem with passlib and not Pyinstaller since I get import errors in Aptana too. One way to work around the issue and still package with a single file (-F) is the following:

Find the python file for the encryption you want in the passlib/handlers source, and copy it to your project.

Then just import it directly form the .py file, for me I used "sha256_crypt" like so.

from sha2_crypt import sha256_crypt

I compiled with Pyinstaller and both below functions work.

```
def GEN_PASS(self, password):
    passWord = sha256_crypt.encrypt(password)
    return passWord

def VERIFY_PASS(self, passRaw, passHash):
    passWord = sha256_crypt.verify(passRaw, passHash)
    return passWord
```

Enjoy!

**Original date**: 2014/06/16
**Original reporter**: _AndCycle_

or using direct import to use the function that won't confuse proxy,

```
import passlib.handlers.sha2_crypt

passWord = passlib.handlers.sha2_crypt.sha256_crypt(passRaw, passHash)
```

This feature-request if five years old now. Nobody worked on it, so I'm closing it. If somebody wants to implement this, feel free to provide a pull-request.
Just spent 3 hrs trying to get passlib to work with pyinstaller. hidden-imports, adding random import + other statements to script, and many variations thereof. nothing worked. finally, I just manually copied the entire passlib directory to the target build directory

Resolving patch:
diff --git a/PyInstaller/hooks/hook-passlib.py b/PyInstaller/hooks/hook-passlib.py
new file mode 100644
--- /dev/null
+++ b/PyInstaller/hooks/hook-passlib.py
@@ -0,0 +1,17 @@
+#-----------------------------------------------------------------------------
+# Copyright (c) 2013-2019, PyInstaller Development Team.
+#
+# Distributed under the terms of the GNU General Public License with exception
+# for distributing bootloader.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+# Handlers are imported by a lazy-load proxy, based on a
+# name-to-package mapping. Collect all handlers to ease packaging.
+# If you want to reduce the size of your application, used
+# `--exclude-module` to remove unused ones.
+hiddenimports = [
+    "passlib.handlers",
+    "passlib.handlers.digests",
+]


Test patch: