更新升级后出现语法错误python3

更新升级后出现语法错误python3

当我运行命令时 sudo apt update && sudo apt upgrade,一切都会像往常一样升级,但最后我收到错误

/usr/lib/python3/dist-packages/pyVNC/Client.py:61: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if event is "Left":
/usr/lib/python3/dist-packages/pyVNC/Client.py:63: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif event is "Middle":
/usr/lib/python3/dist-packages/pyVNC/Client.py:65: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif event is "Right":
/usr/lib/python3/dist-packages/pyVNC/Client.py:61: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if event is "Left":
/usr/lib/python3/dist-packages/pyVNC/Client.py:63: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif event is "Middle":
/usr/lib/python3/dist-packages/pyVNC/Client.py:65: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif event is "Right"

我尝试查看代码,但什么也没想到。关于如何修复有什么想法吗?

答案1

首先,是的,这是一个警告,而不是错误,这是因为您可能正在使用这个库https://github.com/cair/pyVNC

和这部分(/usr/lib/python3/dist-packages/pyVNC/Client.py:61) 发出警告:

if event is "Left":
    button_id = 1
elif event is "Middle":
    button_id = 2
elif event is "Right":
    button_id = 4

正如消息中所述,他们应该使用“==”而不是“is”,请参阅本文以获取更多信息https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

另一件事是为什么在更新操作系统时会引发此问题,可能是因为您没有为 python 脚本使用 virtualenv。所以我建议你这样做:https://docs.python.org/3/library/venv.html

相关内容