[报错] SyntaxError: Missing parentheses in call to ‘exec‘

报错信息

在 Debug Python 程序的时候(PyCharm),直接就报了以下错误:

ImportError: cannot import name 'InteractiveConsole' from 'code' (/home/xovee/Desktop/contrastive_cascade/code/__init__.py)
...
SyntaxError: Missing parentheses in call to 'exec'

完整报错代码

/home/xovee/anaconda3/envs/tf22cuda101/bin/python /snap/pycharm-community/202/plugins/python-ce/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 46645 --file /home/xovee/Desktop/contrastive_cascade/code/cgc_distillation.py
Traceback (most recent call last):
  File "/snap/pycharm-community/202/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_console_integration.py", line 4, in <module>
    from code import InteractiveConsole
ImportError: cannot import name 'InteractiveConsole' from 'code' (/home/xovee/Desktop/contrastive_cascade/code/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/snap/pycharm-community/202/plugins/python-ce/helpers/pydev/pydevd.py", line 39, in <module>
    from _pydevd_bundle.pydevd_comm import CMD_SET_BREAK, CMD_SET_NEXT_STATEMENT, CMD_STEP_INTO, CMD_STEP_OVER, \
  File "/snap/pycharm-community/202/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 91, in <module>
    from _pydevd_bundle import pydevd_console_integration
  File "/snap/pycharm-community/202/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_console_integration.py", line 6, in <module>
    from _pydevd_bundle.pydevconsole_code_for_ironpython import InteractiveConsole
  File "/snap/pycharm-community/202/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevconsole_code_for_ironpython.py", line 305
    exec code in self.locals
            ^
SyntaxError: Missing parentheses in call to 'exec'

Process finished with exit code 1

环境

  • Python 3.7
  • PyCharm 2020.1.3

解决方案

原因是代码所在文件夹被命名为 code,所以。。。把文件夹的名字改成其他的就可以了,例如 src

Reference

  1. Gulzar. (Jul 27, 2020). pytest exec code in self.locals SyntaxError: Missing parentheses in call to ‘exec’. Retrieved from https://stackoverflow.com/questions/61696180/pytest-exec-code-in-self-locals-syntaxerror-missing-parentheses-in-call-to-exe
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Xovee

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值