我正在我的Windows机器上构建一个带烧瓶的应用程序,我需要导入烧瓶bcrypt,我使用下面的代码行:
from flask.ext.bcrypt import generate_password_hash, check_password_hash
我收到了不支持flask.ext.bcrypt的错误,我应该使用flask_bcrypt代替:
/usr/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.bcrypt is deprecated, use flask_bcrypt instead.
我将代码更改为:
from flask_bcrypt import generate_password_hash, check_password_hash
我又收到了一个错误:
bcrypt is required to use Flask-Bcrypt
Traceback (most recent call last):
File "app.py", line 2, in <module>
from flask_bcrypt import generate_password_hash, check_password_hash
File "/usr/lib/python2.7/site-packages/Flask_Bcrypt-0.7.1-py2.7.egg /flask_bcrypt.py", line 27, in <module>
raise e
ImportError: No module named bcrypt
使用 pip show flask-bcrypt 它显示我在我的机器上安装了flask-bcrypt并且我还安装了flask:
» pip show flask-bcrypt
---
Metadata-Version: 1.1
Name: Flask-Bcrypt
Version: 0.7.1
Summary: Brcrypt hashing for Flask.
Home-page: https://github.com/maxcountryman/flask-bcrypt
Author: Max Countryman
Author-email: maxc@me.com
License: BSD
Location: /usr/lib/python2.7/site-packages/Flask_Bcrypt-0.7.1-py2.7.egg
Requires: Flask, bcrypt
Classifiers:
Environment :: Web Environment
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Topic :: Internet :: WWW/HTTP :: Dynamic Content
Topic :: Software Development :: Libraries :: Python Modules
请问我做得对不对?我在网上搜索了很多与flask-bcrypt相关的问题而没有帮助。
除了上面的内容之外,我用pip安装了几次bcrypt以确保它已正确安装,但每次都出现以下错误:
No package 'libffi' found
c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^
compilation terminated.
raise DistutilsError("Setup script exited with %s" % (v.args[0],))
distutils.errors.DistutilsError: Setup script exited with error: command 'gcc' failed with exit st atus 1
----------------------------------------
Failed building wheel for bcrypt
No package 'libffi' found
c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^
compilation terminated.
答案 0 :(得分:0)
bcrypt
依赖的flask-bcrypt
扩展程序未正确安装在您的系统上。请使用pip
明确安装。
您可能需要编译器才能安装它。安装flask-bcrypt
时,您可能会在屏幕上闪烁某种错误消息。
此外,对于Windows计算机,您的路径看起来有点奇怪。您是否在Windows上使用Uashntu上的Bash?在这种情况下,你实际上是在使用Ubuntu。