【问题标题】:Why missing parenthesis error in print Python2.7. When python 2.7 support no brackets?为什么在打印 Python2.7 时缺少括号错误。 python 2.7什么时候不支持括号?
【发布时间】:2023-03-03 12:44:02
【问题描述】:

我正在运行 NVMain,但遇到了 python 错误。我正在使用 python 2.7.18,但最终出现了缺少括号的错误,并且当我到处阅读时,python 2.7 不支持括号,但为什么该错误仍然存​​在。我附上一张错误的图片。

【问题讨论】:

  • 你在使用 virtualenv 吗?您是如何安装 SCons 的?

标签: python-2.7 scons nvmain


【解决方案1】:

您没有使用 Python 2.7。您正在使用scons,它正在选择自己的解释器(我假设它是一个脚本,所以您可以在文本编辑器中打开它,它可能在顶部有一个指向python3 的shebang 行) .从scons 4.0.0 版开始,它根本不支持低于 3.5 的 Python,因此您的 SConscript 文件需要使用 Python 3 兼容的语法编写。

【讨论】:

  • 好的...我刚刚将 python 从 2.7 更改为 3.8,但同样的问题仍然存在。为什么? umakant@umakant-Vostro-15-3568:~/$ python -V Python 3.8.5 umakant@umakant-Vostro-15-3568:~/gem5-nvmain-hybrid-simulator-master/nvmain$ scons --build-type =fast scons:读取 SConscript 文件...文件“/home/umakant/gem5-nvmain-hybrid-simulator-master/nvmain/build/SConscript”,第 57 行打印“检查 gem5 修订号...”,^ SyntaxError:调用“打印”时缺少括号。你的意思是 print("Checking gem5 revision number...", end=" ")?
  • @Learning 不,你搞错了。无括号 printPython 2 构造,在 Python 3 中无效。问题是 scons 使用 Python 3 运行您的代码,而不是 2。
  • @Learning:正如我在答案中所说,将您的scons 相关代码(例如SConscript)重写为与 Python 3 兼容,例如使用 print 函数(需要括号),而不是 print 语句(仅 Python 2 的怪异)。 2to3 帮助器可能会为您做很多事情,但是您可能需要更改的所有可能的事情都超出了 StackOverflow 的范围;有一些大的、烦人的事情要处理,还有几十个小的、大部分是可自动化的变化。
猜你喜欢
  • 2018-10-13
  • 1970-01-01
  • 2020-01-09
相关资源
最近更新 更多