【问题标题】:"ImportError: No module named pwd" but it exists“ImportError:没有名为 pwd 的模块”但它存在
【发布时间】:2013-09-20 02:33:08
【问题描述】:

我正在尝试在本地测试 gae-boilerplate,但是当我尝试创建新帐户时出现以下错误。

奇怪的是,如果我打开 python 解释器并输入“import pwd”,它就可以工作。

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

【问题讨论】:

  • 你不能在应用引擎上使用pwd模块,所以开发服务器也不会让你使用它。
  • 你也不能在windows上使用pwd模块。

标签: python macos google-app-engine python-2.7 pwd


【解决方案1】:

我相信这个问题是由 AppEngine SDK 更新引入的。我目前使用的是 1.8.6 版。 gae-boilerplate README 声明它已“使用 SDK 版本 1.8.1 测试”

我可以通过运行 old_dev_appserver.py &lt;application root&gt;old_dev_appserver.py 来在本地运行它,它由 SDK 提供,与 dev_appserver.py 位于同一目录中。

根据我得到的回溯,看起来文件boilerplate/external/requests/utils.py 导入了netrc,它导入了pwd。 较新版本的 SDK 不允许您在沙盒模式下导入 pwd 模块。

【讨论】:

  • 我在这里找不到old_dev_appserver.py/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools
【解决方案2】:

您可能使用easy_install 安装了pycrypto。如果你用pip 重新安装它,一切都应该工作:

pip uninstall pycrypto
pip install pycrypto

注意,pip uninstall 可以使用,即使它是使用easy_install 安装的。您可能还需要使用sudo

如果你没有pip,像这样安装它:

sudo easy_install pip

【讨论】:

猜你喜欢
  • 2021-04-15
  • 1970-01-01
  • 2019-04-24
  • 1970-01-01
  • 1970-01-01
  • 2015-08-25
  • 2015-04-24
  • 2018-11-02
  • 2013-03-11
相关资源
最近更新 更多