简体   繁体   English

在Python 3中使用导入保管箱时出现语法错误

[英]Syntax error when using import dropbox in Python 3

I'm trying to use Dropbox with Python 3. It appears to install OK but when I try to import it, I get a syntax error (see below). 我正在尝试将Dropbox与Python 3结合使用。它似乎安装得不错,但是当我尝试导入它时,出现语法错误(请参见下文)。 It's only supported on 3.4+ and I'm using 3.2... I wondered if that's the problem but I found a website (in the original German or in English using Google Translate which doesn't get the formatting quite right) which is using Dropbox with Python 3.2 on a Raspberry Pi - and that's exactly what I want to do. 它仅在3.4+上受支持,而我正在使用3.2 ...我想知道这是否是问题,但是我找到了一个正在使用的网站(使用Google Translate的原始德语英语版本 ,但格式不正确)在Raspberry Pi上使用Python 3.2的Dropbox-这正是我想要做的。

Thanks in advance - any help or suggestions would be appreciated. 预先感谢-任何帮助或建议,将不胜感激。

pi@jsmd ~ $ sudo pip-3.2 install --upgrade dropbox
Requirement already up-to-date: dropbox in /usr/local/lib/python3.2/dist-packages/dropbox-4.0-py3.2.egg
Requirement already up-to-date: urllib3 in /usr/local/lib/python3.2/dist-packages (from dropbox)
Requirement already up-to-date: requests>=2.5.1 in /usr/local/lib/python3.2/dist-packages (from dropbox)
Requirement already up-to-date: six>=1.3.0 in /usr/local/lib/python3.2/dist-packages (from dropbox)
Cleaning up...

pi@jsmd ~ $ python3.2
Python 3.2.3 (default, Mar  1 2013, 11:53:50)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import dropbox
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/dropbox-4.0-py3.2.egg/dropbox/__init__.py", line 3, in <module>
    from .dropbox import __version__
  File "/usr/local/lib/python3.2/dist-packages/dropbox-4.0-py3.2.egg/dropbox/dropbox.py", line 19, in <module>
    from .base import DropboxBase
  File "/usr/local/lib/python3.2/dist-packages/dropbox-4.0-py3.2.egg/dropbox/base.py", line 7, in <module>
    from . import (
  File "/usr/local/lib/python3.2/dist-packages/dropbox-4.0-py3.2.egg/dropbox/files.py", line 5157
    Metadata._parent_shared_folder_id_validator = bv.Nullable(bv.String(pattern=u'[-_0-9a-zA-Z:]+'))
                                                                                                 ^
SyntaxError: invalid syntax

The current version of the provided Dropbox Python SDK uses the u'...' notation to define Unicode literals. 提供的Dropbox Python SDK的当前版本使用u'...'表示法定义Unicode文字。 This is a syntax introduced in Python 3.3 to assist in writing code that works both on Python 2 and 3. 这是Python 3.3中引入的一种语法,可帮助编写可在Python 2和3上运行的代码。

The blog post doesn't detail how they managed to skirt the minimum requirements; 博客文章没有详细介绍他们如何设法满足最低要求。 I can only think that the library has been updated to take advantage of newer Python features to simplify polyglot Python code after the post was published . 我只能认为该库已更新,可以利用发布后发布的 Python新功能来简化多语言Python代码。

The current dropbox package version is 4.0; 当前的dropbox软件包版本是4.0。 take a look through the versions on the simple pypi page for the package and see if an earlier version works for you, instead. 请查看该软件包简单pypi页上的版本,然后查看较早的版本是否适合您。

I'm not sure the version the blog used is available though. 我不确定博客使用的版本是否可用。 Version 3.12 was published to PyPI in August 2015, so well after May 2015 (when the blog post was posted) and already requires Python 3.3 or newer (judging by the initial API v2 commit on Github ). 3.12版已于2015年8月发布到PyPI,因此在2015年5月(发布博客文章)之后就已经很好了,并且已经需要Python 3.3或更高版本(根据Github上最初API v2 commit判断)。 The next older release is version 2.2.0 , which goes back to September 2014 and uses Dropbox API version 1. 下一个较旧的版本是2.2.0版 ,该版本可以追溯到2014年9月,并使用Dropbox API版本1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM