微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

安装 autopy 时出现“SyntaxError: invalid syntax”

如何解决安装 autopy 时出现“SyntaxError: invalid syntax”

我需要运行需要 autopy 的代码(对于 python 2.7)

Python 2.7

setuptools-rust 0.11.4

自动 4.0.0

C:\pip install autopy
DEPRECATION: Python 2.7 will reach the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip,can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting autopy
  Using cached https://files.pythonhosted.org/packages/3d/3e/e589bfe03c7ee1c3d832dda10b908557f25a09d66acfc8fc7d982ee23d1a/autopy-4.0.0.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\unitedsalvatore\appdata\local\python\python27\python.exe' -c 'import sys,setuptools,tokenize; sys.argv[0] = '"'"'c:\\users\\united~1\\appdata\\local\\temp\\pip-install-j55cvn\\autopy\\setup.py'"'"'; __file__='"'"'c:\\users\\united~1\\appdata\\local\\temp\\pip-install-j55cvn\\autopy\\setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__);code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: c:\users\united~1\appdata\local\temp\pip-install-j55cvn\autopy\
    Complete output (10 lines):
    Traceback (most recent call last):
      File "<string>",line 1,in <module>
      File "c:\users\united~1\appdata\local\temp\pip-install-j55cvn\autopy\setup.py",line 8,in <module>
        from setuptools_rust import Binding,RustExtension
      File "c:\users\unitedsalvatore\appdata\local\python\python27\lib\site-packages\setuptools_rust\__init__.py",in <module>
        from .tomlgen import tomlgen_rust,find_rust_extensions
      File "c:\users\unitedsalvatore\appdata\local\python\python27\lib\site-packages\setuptools_rust\tomlgen.py",line 191
        yield dep,toml.loads(f"{dep} = {options}")[dep]
                                                 ^
    SyntaxError: invalid Syntax
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.3,however version 20.3.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

为什么我会看到这个错误?我是python的新手

解决方法

安装代码使用格式字符串(f-strings),仅 Python 3.6+ 支持。由于您使用的是 Python 2.7,它无法识别这一点并引发语法错误。要解决此问题,您至少需要升级到 Python 3.6 或更高版本。

有关详细信息,Real Python 有一篇好文章 here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。