【问题标题】:Module not found when debugging调试时找不到模块
【发布时间】:2020-11-21 08:15:50
【问题描述】:

我正在使用 PyCharm 运行 Python 客户端。如果我只是运行它,PyCharm 只需调用:

C:\Python27\python.exe E:/faf/client/src

一切都很好。

这些是我的设置:

如果我想调试它,PyCharm 调用:

C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.2\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 52948 --file E:/faf/client/src

结果是实际上存在的模块不能被包含

pydev debugger: process 5092 is connecting

Connected to pydev debugger (build 143.1184)
Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.2\helpers\pydev\pydevd.py", line 2407, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.2\helpers\pydev\pydevd.py", line 1798, in run
    launch(file, globals, locals)  # execute the script
  File "E:/faf/client/src\__main__.py", line 29, in <module>
    import config
ImportError: No module named config

我需要做什么才能调试这个东西?

【问题讨论】:

  • 您是否尝试使用 src 指定工作目录?什么是配置?文件在同一个目录吗?
  • @Andrey 是的,这确实是问题所在。我认为我必须这样做很奇怪,因为这样做之后,运行配置中没有任何明显的变化 O_o 尽管有两次接近投票,但我不会删除我的答案,因为人们怎么会知道这一点?
  • 我猜python.exe使用py文件的文件夹作为工作目录,而“pydevd.py”以某种方式设置工作目录并且在命令行中是不可见的
  • @Andrey 是的,不幸的是这并不明显 ^^ 但是感谢您的帮助! :)

标签: python pycharm


【解决方案1】:

我必须单击 src 目录并将其添加为源文件夹 (Mark Directory As -&gt; Source Root)。没有明显的变化,例如调用python命令的方式。

因此,如果您有类似的问题,请尝试这样做。

【讨论】:

  • 不适用于google-auth 1.6.1 (used with import google.auth)PyCharm 2018.3 Professional 中的错误仍然相同
【解决方案2】:

我通过在我尝试导入的模块的文件夹中添加 init.py 为自己解决了这个问题。

【讨论】:

    猜你喜欢
    • 2019-05-24
    • 2016-08-05
    • 2018-03-10
    • 1970-01-01
    • 2015-10-28
    • 2012-12-13
    • 2019-11-19
    • 1970-01-01
    • 2019-06-05
    相关资源
    最近更新 更多