微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在我的 python 3 环境中运行 bcrpyt 或 werkzeug

如何解决无法在我的 python 3 环境中运行 bcrpyt 或 werkzeug

我正在做一个关于flask和python 3的课程。我在requirements.txt文件中设置了一个python 3.6环境,其中包含以下库:

alembic==0.9.9
blinker==1.4
chardet==3.0.4
click==6.7
Flask==1.0.2
Flask-Dance==0.14.0
Flask-DebugToolbar==0.10.1
Flask-Login==0.4.1
Flask-Migrate==2.1.1
Flask-OAuth==0.12
Flask-OAuthlib==0.9.4
Flask-sqlAlchemy==2.3.2
Flask-WTF==0.14.2
httplib2==0.11.3
idna==2.6
itsdangerous==0.24
Jinja2==2.10
lazy==1.3
Mako==1.0.7
MarkupSafe==1.1.1
oauth2==1.9.0.post1
oauthlib==2.0.7
python-dateutil==2.7.2
python-editor==1.0.3
requests==2.18.4
requests-oauthlib==0.8.0
six==1.11.0
sqlAlchemy==1.2.6
sqlAlchemy-Utils==0.33.2
urllib3==1.22
URLObject==2.4.3
Werkzeug==0.14.1
wincertstore==0.2
WTForms==2.1

我正在尝试在环境中运行此脚本:

#pip install flask-bcrypt
from flask_bcrypt import Bcrypt

# Create the Hasher
bcrypt = Bcrypt()

hashed_pass = bcrypt.generate_password_hash('mypassword')
print(hashed_pass)
wrong_check = bcrypt.check_password_hash(hashed_pass,'wrongpass')
print(wrong_check)
right_check = bcrypt.check_password_hash(hashed_pass,'mypassword')
print(right_check)

但我收到此错误

(myflaskenv2) C:\Users\dthomas\Documents\python_projects\Python and Flask Bootcamp\authentication>bcrypt-attempt.py
Traceback (most recent call last):
  File "C:\Users\dthomas\Documents\python_projects\Python and Flask Bootcamp\authentication\bcrypt-attempt.py",line 2,in <module>
    from flask_bcrypt import Bcrypt
ModuleNotFoundError: No module named 'flask_bcrypt'

同样,当我尝试使用 werkzeug 脚本时:

# pip install Werkzeug
from werkzeug.security import generate_password_hash,check_password_hash

# Can add options to this like salt and method
# For example: method='pbkdf2:sha256',salt_length=8 (these are defaults)
hashed_pass = generate_password_hash('mypassword')
print(hashed_pass)
wrong_check = check_password_hash(hashed_pass,'wrong')
print(wrong_check)
right_check = check_password_hash(hashed_pass,'mypassword')
print(right_check)

我收到此错误

Traceback (most recent call last):
  File "C:\Users\dthomas\Documents\python_projects\Python and Flask Bootcamp\authentication\werkzeug-attempt.py",in <module>
    from werkzeug.security import generate_password_hash,check_password_hash
ModuleNotFoundError: No module named 'werkzeug'

我试过了:

  • 重新创建新环境
  • 卸载、安装不同的
  • pip2 和 pip3 中的 werkzeug 版本,包括
    的内部和外部 环境
  • 在不同的计算机上尝试过

有人知道这个问题吗?

解决方法

也许你应该尝试升级 Werkzeug,我的是 Werkzeug==2.0.0 和 Flask==2.0.0。好像是版本问题。试试:

pip install --upgrade werkzeug

另外,您的requirements.txt中似乎没有flask_bcrypt,您可以查看安装详细信息here

pip install Flask-Bcrypt

现在,再试一次。 您可能还想升级 Flask:

pip install --upgrade Flask
,

哇,这太尴尬了。

我输入的是 attempt-werkzeug.py 而不是 python attempt-werkzeug.py

抱歉打扰了

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。