我正在尝试使用另一位用户发布的以下内容作为对其他问题的答案:

>>> # import the hash algorithm
>>> from passlib.hash import sha256_crypt

>>> # generate new salt, and hash a password
>>> hash = sha256_crypt.encrypt("toomanysecrets")
>>> hash

但是,当我键入from passlib.hash import sha256_crypt时,出现以下错误:
Traceback (most recent call last):   File "<stdin>", line 1, in
<module> ImportError: No module named passlib.hash
>>>

我已经完成了pip install passlib。有任何想法吗?

运行结果: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

最佳答案

您会收到“权限被拒绝”错误。尝试

sudo pip install passlib

或者
pip install --user passlib

关于python - 使用Python passlib创建密码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22025260/

10-10 14:45