google-api-python-client不起作用,使Spyder在启动时失败

时间:2013-05-07 11:25:21

标签: python google-api translation google-api-python-client spyder

我使用

在我的Ubuntu 13.04上安装了google-api-python-client
sudo easy_install --upgrade google-api-python-client

据说here

之后我尝试用它来翻译python中的东西。我从here获取了代码。

>>> from apiclient.discovery import build
>>> service = build('translate', 'v2', developerKey='MyApiKey')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.1-py2.7.egg/oauth2client/util.py", line 128, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.1-py2.7.egg/apiclient/discovery.py", line 192, in build
    resp, content = http.request(requested_url)
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.8-py2.7.egg/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.8-py2.7.egg/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.8-py2.7.egg/httplib2/__init__.py", line 1252, in _conn_request
    conn.connect()
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.8-py2.7.egg/httplib2/__init__.py", line 1021, in connect
    self.disable_ssl_certificate_validation, self.ca_certs)
  File "/usr/local/lib/python2.7/dist-packages/httplib2-0.8-py2.7.egg/httplib2/__init__.py", line 80, in _ssl_wrap_socket
    cert_reqs=cert_reqs, ca_certs=ca_certs)
  File "/usr/lib/python2.7/ssl.py", line 440, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 198, in __init__
    ciphers)
ssl.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

有什么问题?

实际上,我首先想在Spyder中做到这一点,但它未能开始:

ilya@ilya-laptop:~/Projects/online-translator$ spyder
Traceback (most recent call last):
  File "/usr/bin/spyder", line 3, in <module>
    start_app.main()
  File "/usr/lib/python2.7/dist-packages/spyderlib/start_app.py", line 64, in main
    from spyderlib import spyder
  File "/usr/lib/python2.7/dist-packages/spyderlib/spyder.py", line 97, in <module>
    from spyderlib.plugins.inspector import ObjectInspector
  File "/usr/lib/python2.7/dist-packages/spyderlib/plugins/inspector.py", line 36, in <module>
    from spyderlib.widgets.ipython import IPythonControlWidget
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/ipython.py", line 12, in <module>
    from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
  File "/usr/lib/python2.7/dist-packages/IPython/frontend/qt/console/rich_ipython_widget.py", line 20, in <module>
    from ipython_widget import IPythonWidget
  File "/usr/lib/python2.7/dist-packages/IPython/frontend/qt/console/ipython_widget.py", line 25, in <module>
    from frontend_widget import FrontendWidget
  File "/usr/lib/python2.7/dist-packages/IPython/frontend/qt/console/frontend_widget.py", line 10, in <module>
    from pygments.lexers import PythonLexer
  File "/usr/lib/python2.7/dist-packages/pygments/lexers/__init__.py", line 18, in <module>
    from pygments.plugin import find_plugin_lexers
  File "/usr/lib/python2.7/dist-packages/pygments/plugin.py", line 39, in <module>
    import pkg_resources
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2823, in <module>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 710, in subscribe
    callback(dist)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2823, in <lambda>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2255, in activate
    self.insert_on(path)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2362, in insert_on
    self.check_version_conflict()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2401, in check_version_conflict
    for modname in self._get_metadata('top_level.txt'):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2249, in _get_metadata
    for line in self.get_metadata_lines(name):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1219, in get_metadata_lines
    return yield_lines(self.get_metadata(name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1211, in get_metadata
    return self._get(self._fn(self.egg_info,name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1326, in _get
    stream = open(path, 'rb')
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.1-py2.7.egg/EGG-INFO/top_level.txt'
Traceback (most recent call last):
  File "/usr/bin/spyder", line 3, in <module>
    start_app.main()
  File "/usr/lib/python2.7/dist-packages/spyderlib/start_app.py", line 64, in main
    from spyderlib import spyder
  File "/usr/lib/python2.7/dist-packages/spyderlib/spyder.py", line 97, in <module>
    from spyderlib.plugins.inspector import ObjectInspector
  File "/usr/lib/python2.7/dist-packages/spyderlib/plugins/inspector.py", line 36, in <module>
    from spyderlib.widgets.ipython import IPythonControlWidget
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/ipython.py", line 12, in <module>
    from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
  File "/usr/lib/python2.7/dist-packages/IPython/frontend/qt/console/rich_ipython_widget.py", line 20, in <module>
    from ipython_widget import IPythonWidget
  File "/usr/lib/python2.7/dist-packages/IPython/frontend/qt/console/ipython_widget.py", line 25, in <module>
    from frontend_widget import FrontendWidget
  File "/usr/lib/python2.7/dist-packages/IPython/frontend/qt/console/frontend_widget.py", line 10, in <module>
    from pygments.lexers import PythonLexer
  File "/usr/lib/python2.7/dist-packages/pygments/lexers/__init__.py", line 18, in <module>
    from pygments.plugin import find_plugin_lexers
  File "/usr/lib/python2.7/dist-packages/pygments/plugin.py", line 39, in <module>
    import pkg_resources
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2823, in <module>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 710, in subscribe
    callback(dist)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2823, in <lambda>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2255, in activate
    self.insert_on(path)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2362, in insert_on
    self.check_version_conflict()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2401, in check_version_conflict
    for modname in self._get_metadata('top_level.txt'):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2249, in _get_metadata
    for line in self.get_metadata_lines(name):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1219, in get_metadata_lines
    return yield_lines(self.get_metadata(name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1211, in get_metadata
    return self._get(self._fn(self.egg_info,name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1326, in _get
    stream = open(path, 'rb')
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.1-py2.7.egg/EGG-INFO/top_level.txt'

所以不知何故,google_api_python_client会干扰它的启动。 WTF的谷歌API绑定错误?或者和我在一起?

请帮助。

1 个答案:

答案 0 :(得分:4)

从尝试启动Spyder时收到的追溯,看起来Google API Python客户端无法使用正确的权限进行安装。更确切地说,Spyder正在尝试从IPython加载组件,这些组件使用了Pygments语法高亮显示器。 Pygments尝试使用pkg_resources模块自动发现包,但由于权限问题,它无法读取google_api_python_client蛋。我怀疑如果你试图以root身份运行Spyder,它可能会启动。

显然,这个问题有很多潜在的来源。这可能是因为Google软件包根本没有正确构建,如here所述,或者可能是您有setuptools的另一个版本在某处徘徊,如here所述。您可以尝试删除google_api_python_client并通过pip重新安装。无论如何,删除google_api_python_client应该允许Spyder再次正常启动。