【问题标题】:Executing python script from Jenkins job giving 'SyntaxError: invalid syntax' error从 Jenkins 作业执行 python 脚本给出“SyntaxError:无效语法”错误
【发布时间】:2021-05-18 09:57:53
【问题描述】:

下面是我的 python 脚本中的 sn-p,它在 pycharm 中运行良好,但如果从 Jenkins 作业的 Execute shell 运行,则作业失败并显示错误提示 SyntaxError: invalid syntaxCURRENT_MONTH: Final = "cur_mon"

from typing import Final

CURRENT_MONTH: Final = "cur_mon"
LAST_MONTH: Final = "last_mon"
data_timeline = [CURRENT_MONTH, LAST_MONTH]

在 Jekins 作业中使用的命令是 python my_file.pypyhton3 my_file.py。在这两种情况下,它都失败并出现相同的错误。

请告知这里可能出了什么问题。

【问题讨论】:

    标签: python python-3.x jenkins


    【解决方案1】:

    您的 Jenkins 正在运行 Python < 3.6。变量注解语法来自 Python 3.6:

    https://www.python.org/dev/peps/pep-0526/

    另外,Final 在 Python 中引入了 3.8(但缺少它当然会引发 ImportError 而不是 SyntaxError):

    https://www.python.org/dev/peps/pep-0591/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-11
      • 2013-04-19
      • 2015-06-20
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多