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

Cannot run bcrpyt or werkzeug in my python 3 environment

我正在使用 Flask 和 python 3. 我已经设置了一个 python 3.6 环境,在 requirement.txt 文件中包含以下库:

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", line 2, in <module>
    from werkzeug.security import generate_password_hash,check_password_hash
ModuleNotFoundError: No module named '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

抱歉造成混淆