"ImportError: No module named pwd" but it exists

I'm trying to test gae-boilerplate locally, but when I try to create a new account the following error appears.

The strange thing is that if I open python interpreter and type "import pwd" it works.

Internal Server Error

The server has either erred or is incapable of performing the requested operation.

Traceback (most recent call last):   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()   File "/Users/moisesguimaraes/workspaces/python/mtgtradelist/boilerplate/lib/basehandler.py", line 88, in dispatch
    webapp2.RequestHandler.dispatch(self)   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)   File "/Users/moisesguimaraes/workspaces/python/mtgtradelist/boilerplate/handlers.py", line 766, in post
    password = utils.hashing(password, self.app.config.get('salt'))   File "/Users/moisesguimaraes/workspaces/python/mtgtradelist/boilerplate/lib/utils.py", line 38, in hashing
    from Crypto.Cipher import AES   File "/Library/Python/2.7/site-packages/pycrypto-2.6-py2.7-macosx-10.8-intel.egg/Crypto/Cipher/AES.py", line 50, in <module>   File "/Library/Python/2.7/site-packages/pycrypto-2.6-py2.7-macosx-10.8-intel.egg/Crypto/Cipher/_AES.py", line 7, in <module>   File "/Library/Python/2.7/site-packages/pycrypto-2.6-py2.7-macosx-10.8-intel.egg/Crypto/Cipher/_AES.py", line 4, in __bootstrap__   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 882, in resource_filename
    self, resource_name   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 1351, in get_resource_filename
    self._extract_resource(manager, self._eager_to_zip(name))   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 1373, in _extract_resource
    self.egg_name, self._parts(zip_path)   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 957, in get_cache_path
    extract_path = self.extraction_path or get_default_cache()   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 1080, in get_default_cache
    return os.path.expanduser('~/.python-eggs')   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 259, in expanduser
    import pwd   File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 835, in load_module
    raise ImportError('No module named %s' % fullname) ImportError: No module named pwd

I believe this problem was introduced by an AppEngine SDK update. I'm currently using version 1.8.6. The gae-boilerplate README states that its been "Tested with SDK version 1.8.1"

I was able to run it locally by running old_dev_appserver.py <application root> old_dev_appserver.py is provided by the SDK and is located in the same directory as dev_appserver.py.

Based on the traceback I got, it looks like the file boilerplate/external/requests/utils.py imports netrc which imports pwd. The newer version of the SDK doesn't allow you to import the pwd module in its sandbox mode.


You probably installed pycrypto with easy_install . If you reinstalling it with pip instead, everything should work:

pip uninstall pycrypto
pip install pycrypto

Note, pip uninstall works even though it was installed with easy_install . You also might need to use sudo .

If you don't have pip , install it like this:

sudo easy_install pip
链接地址: http://www.djcxy.com/p/74292.html

上一篇: 将字符串转换为undefined / null / number / boolean

下一篇: “ImportError:没有名为pwd的模块”,但它存在