0

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

sudo easy_install --upgrade google-api-python-client

正如这里所说。

之后,我尝试用它在 python 中翻译一些东西。我从这里拿了代码。

>>> 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 与 google API 绑定到 python 有问题吗?还是和我一起?

请帮忙。

4

1 回答 1

4

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

显然,这个问题有多个潜在来源。这可能是因为谷歌包根本没有正确构建,如此所述,或者可能是您在某个地方有另一个版本setuptools如此处所述。您可以尝试通过. 在任何情况下,删除应该允许 Spyder 再次正常启动。google_api_python_clientpipgoogle_api_python_client

于 2013-05-07T12:20:48.290 回答