简体   繁体   English

VS Code Debugger:导入错误,没有名为scrapy的模块

[英]VS Code Debugger: Import error, no module named scrapy

I am able to run all the scrapy spiders on vs code without any error.我能够在 vs 代码上运行所有的爬虫程序,没有任何错误。 But when I try to run the debugger, it raises an exception但是当我尝试运行调试器时,它引发了一个异常

No module named scrapy

I am on MacOS.我在 MacOS 上。 I can properly run scrapy commands from the terminal as well.我也可以从终端正确运行scrapy命令。

Try running your script from cmd in debug mode with尝试在调试模式下从 cmd 运行脚本

python -m debugpy --listen 5678 --wait-for-client ./__main__.py

Make sure to install it using python -m pip install debugpy确保使用python -m pip install debugpy安装它

and then configure a launch.json file in the debugger to attach to the python script listening on port 5678然后在调试器中配置一个launch.json文件附加到监听5678端口的python脚本

{
  "name": "Python: Attach",
  "type": "python",
  "request": "attach",
  "connect": {
    "host": "localhost",
    "port": 5678
  }
}

The complete file will look something like this完整的文件看起来像这样

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            }
        }
    ]
}

After that set the breakpoints in your program and start the debugger from vscode之后在你的程序中设置断点并从 vscode 启动调试器

Also check if the version running during the debug is the same used normally, just create a blank file with the following content还要检查调试时运行的版本是否与正常使用的版本相同,只需创建一个包含以下内容的空白文件

import sys

def main():
    print(sys.version)

if __name__ == "__main__":
    main()

the following will print something like以下将打印类似

3.6.9 (default, Jan 26 2021, 15:33:00) \\n[GCC 8.4.0]

Also check from the statusbar at the bottom of vscode if you have the right python version selected.如果您选择了正确的 python 版本,还可以从 vscode 底部的状态栏检查。

More on the first part here更多关于第一部分在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM