【问题标题】:visual studio code python how to get source code of import module definitianvisual studio code python 如何获取导入模块定义的源代码
【发布时间】:2020-06-11 16:26:50
【问题描述】:

我使用windows WSL调试python源代码 我导入的一些模块我可以看到源代码,有些我不能,为什么我不能?

我在这里尝试找出 WSL 中安装的模块的位置:

[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansible
>>> ansible.__file__
'/home/boo/projects/ansible/lib/ansible/__init__.py'
>>> import site; site.getsitepackages()
['/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']
>>> cd
KeyboardInterrupt
>>>      

在这里我可以看到我无法访问:

在这里我可以看到我可以访问:

我检查了 VSCODE 使用的 python 是否与安装的相同

然后我检查了 WSL:指向:python3 -> python3.8

tst@TEST:~/.local/lib/python3.8/site-packages/ansible/cli$  /bin/python3.8
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansible
>>> ansible.__file__
'/home/tst/.local/lib/python3.8/site-packages/ansible/__init__.py'

解决方案: 设置:

justMyCode:false 

在launch.json中

【问题讨论】:

  • 你能在 VS Code 中导入模块吗?只是为了确认您没有使用正确的环境。
  • 什么意思?
  • 如果你查看状态栏,你确定你选择的环境已经安装了ansible吗?

标签: python debugging visual-studio-code windows-subsystem-for-linux


【解决方案1】:

谢谢!对那些搜索的人来说更完整的答案:确保您的 .vscode 文件夹中有一个 launch.json 文件 - 您可以使用以下说明自动创建一个:https://code.visualstudio.com/docs/python/debugging ...然后在该文件中添加 "justMyCode": false,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 2021-06-09
    • 2019-12-09
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多