首页 > 解决方案 > PyCharm 调试器 - ImportError:无法导入名称 getargspec

问题描述

当我运行 PyCharm 调试器来调试 python 代码时,我收到以下错误消息。测试本身在 PyCharm 和 PyCharm 之外运行良好。我使用 virtualenv 并且之前已经多次使用它,但这是使用 PyCharm、Ubuntu 和 Python 的不同版本的较新设置

版本信息:

Python 2.7.17 PyCharm 2019.3.1(社区版)构建#PC-193.5662.61,构建于 2019 年 12 月 18 日运行时版本:11.0.5+10-b520.17 amd64 VM:JetBrains sro 的 OpenJDK 64 位服务器 VM Linux 5.3.0-24-generic GC:ParNew、ConcurrentMarkSweep 内存:725M 内核:8 注册表:非捆绑插件:

没有可用的 LSB 模块。发行商 ID:Ubuntu 描述:Ubuntu 19.10 发行版:19.10 代号:eoan (venv) jnmcclai@jnmccl

/home/jnmcclai/workspace/adtn_1u_olt/venv/bin/python /snap/pycharm-community/172/plugins/python-ce/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 45823 --file /snap/pycharm-community/172/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py --path /home/jnmcclai/workspace/adtn_1u_olt/test/test_basic_plugin.py
Traceback (most recent call last):
  File "/snap/pycharm-community/172/plugins/python-ce/helpers/pydev/pydevd.py", line 37, 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/172/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/172/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_console_integration.py", line 14, in <module>
    from _pydev_bundle.pydev_code_executor import BaseCodeExecutor
  File "/snap/pycharm-community/172/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_code_executor.py", line 4, in <module>
    from _pydev_bundle._pydev_calltip_util import get_description
  File "/snap/pycharm-community/172/plugins/python-ce/helpers/pydev/_pydev_bundle/_pydev_calltip_util.py", line 20, in <module>
    from _pydev_bundle._pydev_imports_tipper import signature_from_docstring
  File "/snap/pycharm-community/172/plugins/python-ce/helpers/pydev/_pydev_bundle/_pydev_imports_tipper.py", line 9, in <module>
    from inspect import getargspec as _originalgetargspec
ImportError: cannot import name getargspec

Process finished with exit code 1

Empty suite

Empty suite

标签: pythondebuggingpycharm

解决方案


好吧,我能够解决这个问题......

我必须working directory在 PyCharm 运行/调试配置中配置路径。一旦我这样做了,使用调试器时不会发生 getargspect 错误。下面的示例运行/调试配置。

在此处输入图像描述

此外,我们还有一个 pytest.ini 文件,它添加了运行代码覆盖率的选项。这会导致与 PyCharm 的调试器发生冲突,并导致调试器在断点上没有按应有的方式“中断”。所以我必须从我们的 pytest.ini 文件中删除这一行,以使调试器在断点处中断。

addopts = --cov=mcp_general --cov-append --cov-report= --cov-config=.coveragerc
          --doctest-modules -vv --junit-xml .coverage-dir/junit-results.xml

推荐阅读