简体   繁体   中英

Python - Can't import bcrypt in local app engine dev server

I am trying to develop a simple forum site for my udacity assignment. It is not a strict requirement to use the bcrypt for password hashing, but I'd like to do it because I also like to know how to use third party libraries which are not provided by Google.

Following instructions provided here (installing a third-party library), I have created a folder named lib, and installed bcrypt library with following command:

python -m pip install -t lib/ bcrypt

I have the lib folder automatically structred like this:

lib文件夹结构

I also created an appengine_config.py file with following content, as per instructions in above manual:

# appengine_config.py
from google.appengine.ext import vendor

# add lib folder as vendor directory
vendor.add('lib')

At this point, I am unable to import the bcrypt to my scripts. The import commands I tried so far are as follows:


from lib import bcrypt

ImportError: No module named lib



import bcrypt

ImportError: No module named bcrypt._bcrypt



from lib.bcrypt import bcrypt

ImportError: No module named lib.bcrypt


What am I missing?

As Avinash Raj pointed out, and as already pointed out in referenced manual, one cannot use python libraries with c extensions. So I downloaded the py-bcrypt , it worked like a charm.

For any newbie like me who needs it, here is the steps you have to take:

  1. Inside your project folder, create a folder called "lib"
  2. Extract the zip downloaded from github above, to the folder 'lib'. Do not use - in your folder name. Name it something like pybcrypt
  3. Create the appengine_config.py file, as outlined in here
  4. Import the library to your script, like so: from pybcrypt import bcrypt
  5. Pat yourself on the back.

这是另一种选择,您需要先设置Wheel 包,然后才能导入bcrypt

pip install wheel
pip install bcrypt

from flask_bcrypt import Bcrypt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM