vscode python 模块智能感知不起作用

时间:2021-03-15 08:28:52

标签: python visual-studio-code

我正在开发一个具有以下结构的 Python 包:

module_name
  |- __init__.py
  |- app.py
  |- filesystem
     - __init__.py
     - extend_filesystem.py

extend_filesystem.py 包含以下带有显示签名的函数:

function signature

当我尝试在 app.py 中导入模块时,VScode 没有显示任何有用的信息(如参数提示或函数描述)

intellisen screenshot

我安装了 Pylance 扩展,将其设置为服务器语言并为整个工作区设置 Python 的解释器(在我的情况下为 Python 3.7.1 32 位)

我使用的是 Vscode 1.54.2 版

编辑: 在同一目录中,智能感知系统显示所有信息。那么,如何在整个包文件夹中扩展此行为?

1 个答案:

答案 0 :(得分:0)

根据您提供的信息,我在VS Code中进行了测试,您可以参考以下内容:

enter image description here

  1. 当我使用Jedi(默认)作为python的语言服务时:

    enter image description here

    为了保证代码可以运行,我们需要使用:

    <块引用>

    from filesystem.extend_filesystem import extend_file

  2. 当我使用 Pylance 作为 Python 的语言服务时:

    enter image description here

    为了保证代码可以运行,我们需要使用:

    <块引用>
    import sys 
    sys.path.append("./")
    
    from emo.filesystem.extend_filesystem import extend_file
    

另外,建议您区分文件名和函数名,以免导入时混淆。