Creating password using Python passlib
Question: I'm trying to use the following that another user posted as an answer to a
different question:

    
    
    >>> # import the hash algorithm
    >>> from passlib.hash import sha256_crypt
    
    >>> # generate new salt, and hash a password
    >>> hash = sha256_crypt.encrypt("toomanysecrets")
    >>> hash
    

But when I type `from passlib.hash import sha256_crypt` I get the following
error:

    
    
    Traceback (most recent call last):   File "<stdin>", line 1, in
    <module> ImportError: No module named passlib.hash
    >>>
    

I have already done `pip install passlib`. Any ideas?

Result of running: `pip install passlib`:

    
    
    Downloading/unpacking passlib   Downloading passlib-1.6.2.tar.gz (408kB): 408kB downloaded   Running setup.py egg_info for package passlib
    
    Installing collected packages: passlib   Running setup.py install for passlib
        error: could not create '/Library/Python/2.7/site-packages/passlib': Permission denied
        Complete output from command /usr/bin/python -c "import setuptools;__file__='/private/var/folders/2t/1yj5qss57xz8sb7p9wymtkdr0000gn/T/pip_build_<user>/passlib/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/2t/1yj5qss57xz8sb7p9wymtkdr0000gn/T/pip-epiHNK-record/install-record.txt
    --single-version-externally-managed:
        running install
    
    running build
    
    running build_py
    
    creating build
    
    creating build/lib
    
    creating build/lib/passlib
    
    copying passlib/__init__.py -> build/lib/passlib
    
    copying passlib/apache.py -> build/lib/passlib
    
    copying passlib/apps.py -> build/lib/passlib
    
    copying passlib/context.py -> build/lib/passlib
    
    copying passlib/exc.py -> build/lib/passlib
    
    copying passlib/hash.py -> build/lib/passlib
    
    copying passlib/hosts.py -> build/lib/passlib
    
    copying passlib/ifc.py -> build/lib/passlib
    
    copying passlib/registry.py -> build/lib/passlib
    
    copying passlib/win32.py -> build/lib/passlib
    
    creating build/lib/passlib/ext
    
    copying passlib/ext/__init__.py -> build/lib/passlib/ext
    
    creating build/lib/passlib/ext/django
    
    copying passlib/ext/django/__init__.py -> build/lib/passlib/ext/django
    
    copying passlib/ext/django/models.py -> build/lib/passlib/ext/django
    
    copying passlib/ext/django/utils.py -> build/lib/passlib/ext/django
    
    creating build/lib/passlib/handlers
    
    copying passlib/handlers/__init__.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/bcrypt.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/cisco.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/des_crypt.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/digests.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/django.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/fshp.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/ldap_digests.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/md5_crypt.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/misc.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/mssql.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/mysql.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/oracle.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/pbkdf2.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/phpass.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/postgres.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/roundup.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/scram.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/sha1_crypt.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/sha2_crypt.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/sun_md5_crypt.py -> build/lib/passlib/handlers
    
    copying passlib/handlers/windows.py -> build/lib/passlib/handlers
    
    creating build/lib/passlib/tests
    
    copying passlib/tests/__init__.py -> build/lib/passlib/tests
    
    copying passlib/tests/__main__.py -> build/lib/passlib/tests
    
    copying passlib/tests/_test_bad_register.py -> build/lib/passlib/tests
    
    copying passlib/tests/backports.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_apache.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_apps.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_context.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_context_deprecated.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_ext_django.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_handlers.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_handlers_bcrypt.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_handlers_django.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_hosts.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_registry.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_utils.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_utils_crypto.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_utils_handlers.py -> build/lib/passlib/tests
    
    copying passlib/tests/test_win32.py -> build/lib/passlib/tests
    
    copying passlib/tests/tox_support.py -> build/lib/passlib/tests
    
    copying passlib/tests/utils.py -> build/lib/passlib/tests
    
    creating build/lib/passlib/utils
    
    copying passlib/utils/__init__.py -> build/lib/passlib/utils
    
    copying passlib/utils/compat.py -> build/lib/passlib/utils
    
    copying passlib/utils/des.py -> build/lib/passlib/utils
    
    copying passlib/utils/handlers.py -> build/lib/passlib/utils
    
    copying passlib/utils/md4.py -> build/lib/passlib/utils
    
    copying passlib/utils/pbkdf2.py -> build/lib/passlib/utils
    
    creating build/lib/passlib/utils/_blowfish
    
    copying passlib/utils/_blowfish/__init__.py -> build/lib/passlib/utils/_blowfish
    
    copying passlib/utils/_blowfish/_gen_files.py -> build/lib/passlib/utils/_blowfish
    
    copying passlib/utils/_blowfish/base.py -> build/lib/passlib/utils/_blowfish
    
    copying passlib/utils/_blowfish/unrolled.py -> build/lib/passlib/utils/_blowfish
    
    creating build/lib/passlib/_setup
    
    copying passlib/_setup/__init__.py -> build/lib/passlib/_setup
    
    copying passlib/_setup/docdist.py -> build/lib/passlib/_setup
    
    copying passlib/_setup/stamp.py -> build/lib/passlib/_setup
    
    copying passlib/tests/sample1.cfg -> build/lib/passlib/tests
    
    copying passlib/tests/sample1b.cfg -> build/lib/passlib/tests
    
    copying passlib/tests/sample1c.cfg -> build/lib/passlib/tests
    
    copying passlib/tests/sample_config_1s.cfg -> build/lib/passlib/tests
    
    running install_lib
    
    creating /Library/Python/2.7/site-packages/passlib
    
    error: could not create '/Library/Python/2.7/site-packages/passlib': Permission denied
    
    ---------------------------------------- Cleaning up... Command /usr/bin/python -c "import setuptools;__file__='/private/var/folders/2t/1yj5qss57xz8sb7p9wymtkdr0000gn/T/pip_build_<user>/passlib/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/2t/1yj5qss57xz8sb7p9wymtkdr0000gn/T/pip-epiHNK-record/install-record.txt
    --single-version-externally-managed failed with error code 1 in /private/var/folders/2t/1yj5qss57xz8sb7p9wymtkdr0000gn/T/pip_build_<user>/passlib Storing complete log in /Users/<user>/Library/Logs/pip.log
    


Answer: You’re getting a ‘permission denied’ error. Try

    
    
    sudo pip install passlib
    

or

    
    
    pip install --user passlib
    

