Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCrypto on Google App Engine (1.7.0) with Python 2.7 on Mac OS X 10.8 causes ImportError

I am trying to get PyCrypto working with Google App Engine, and I have a lengthy description of an issue I have encountered that is reported as issue 7925 for Google App Engine.

Essentially, I do not know of a sensible way to install PyCrypto on Mac OS X 10.8 in such a way that dev_appserver.py will use it - other than the workaround of putting Crypto/ into the project's root directory.

Unfortunately an issue seems to have just cropped up that causes a project to crash when the project is deployed with Crypto/ in the project's root.

It may be possible to edit or monkeypatch the GAE code, but I am not familiar enough with GAE's code to be comfortable doing that. All of the suggestions I have seen were for Python2.5 and Mac OS X < 10.8.

I would be grateful for thoughts about alternative, sensible ways to get PyCrypto working with the GAE development appserver on Mac OS X 10.8.

like image 569
Brian M. Hunt Avatar asked Aug 03 '12 02:08

Brian M. Hunt


1 Answers

This is the madness I have had to engage in:

  1. Delete all version of PyCrypto

  2. Download PyCrypto v2.3 from https://github.com/dlitz/pycrypto/tags and install with

    dlitz-pycrypto-7e141bd/$ python setup.py build
    dlitz-pycrypto-7e141bd/$ sudo python setup.py install
    

    (version 2.6 balks with a no blockalgo package)

  3. Apply to dev_appserver_import_hook.py in /Application/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/ the patch suggested in comment 1 of Issue 1627, i.e. add

    try:
      import Crypto as _CryptoTest
      _CryptoBase = os.path.dirname(_CryptoTest.__file__).replace(
        os.path.join(os.path.dirname(os.__file__), 'site-packages'),
         "") # removes preceding slash 
      del _CryptoTest
    except ImportError:
      logging.info("No Crypto could be imported")
      _CryptoBase = "Crypto"
    

    around line 314

    then modify the ALLOWED_SITE_PACKAGES lines from

    ALLOWED_SITE_PACKAGE_FILES = set(
        os.path.normcase(os.path.abspath(os.path.join(
        os.path.dirname(os.__file__), 'site-packages', path)))
    

    to

    ALLOWED_SITE_PACKAGE_FILES = set(
        path
    

    and change all references from 'Crypto' to _CryptoBase in the GeneratePythonPaths calls for ALLOWED_SITE_PACKAGES.

    (I would expect if one is using dev_appserver from the command line i.e. /usr/local/google_appengine, the dev_appserver_import_hook.py would be modified there)

  4. Restart the project.

Obviously one must rinse and repeat the patch whenever Google App Engine is updated.


Note — This issue appears to have been fixed as of patch 1.7.4 released 14 Dec. 2012.

like image 77
6 revs, 2 users 88% Avatar answered Nov 07 '22 18:11

6 revs, 2 users 88%