Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app engine: ImportError: No module named Crypto.Hash

I have a script that uses Crypto.Hash but import fails with error:

ImportError: No module named Crypto.Hash

in my sys.path if I print the sys.path list, there is this entry (among others):

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/pycrypto-2.6

If I open the path above, there is no pycrypto-2.6 directory.

How can I get to load pycrypto 2.6?

If I import Crypto.Hash running python from command line it works

I have to point out that pycrypto is supported by App Engine, it is included in this list.

Furthermore I have included the module in my app.yaml file:

libraries:
- name: webapp2
  version: "2.5.2"
- name: pycrypto
  version: latest
- name: lxml
  version: "2.3"
- name: ssl
  version: latest

If I send the code in production on appengine it works, the problem is in my system I should probably download a compiled version of pycrypto and put it somewhere appengine can use it

like image 801
JackNova Avatar asked Mar 30 '15 15:03

JackNova


People also ask

How do I fix No module named Crypto?

The Python "ModuleNotFoundError: No module named 'Crypto'" occurs when we forget to install the pycryptodome module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install pycryptodome command.

How do I install PyCrypto?

PyCrypto is written and tested using Python version 2.1 through 3.3. Python 1.5. 2 is not supported. The modules are packaged using the Distutils, so you can simply run “python setup.py build” to build the package, and “python setup.py install” to install it.


2 Answers

It seems a problem that happens on MAC OSX, all I have managed to do is following:

firstly you need to know where your install of pycripto is, running

sudo pip install pycrypto

either you install the library or you get the path where it is installed

Requirement already satisfied (use --upgrade to upgrade): pycrypto in ...

then, considering that this is a problem that does not happen in production on appengine, I did this:

try:
    from Crypto.Hash import SHA
except ImportError:
    import sys
    sys.path.append('/[mypath]/anaconda/lib/python2.7/site-packages')
    from Crypto.Hash import SHA # requires PyCrypto
like image 124
JackNova Avatar answered Oct 22 '22 00:10

JackNova


Run the SDK from the command line with dev_appserver.py, rather than with the GUI (assuming you've already checked that it's installed via pip).

I've seen similar problems with App Engine not importing libraries locally, even though they're installed, and even though they work fine in production. MySQLDB comes to mind, although I can't find the reference. Anyway, this worked for me.

like image 43
Chris Avatar answered Oct 22 '22 01:10

Chris