Search code examples
pythongoogle-app-enginebcrypt

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:

structre of lib folder

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?


Solution

  • 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.pyfile, as outlined in here
    4. Import the library to your script, like so: from pybcrypt import bcrypt
    5. Pat yourself on the back.