简体   繁体   English

更改 Python 中 VSCode 的默认自动完成导入

[英]Change default autocomplete import for VSCode in Python

I am building a python project using VSCode.我正在使用 VSCode 构建一个 python 项目。 I have a project folder structure that looks like this:我有一个如下所示的项目文件夹结构:

Project
  -> data
  -> src
    -> classes
      -> subfolder1
        -> file1.py
        -> file2.py
      -> subfolder2
  -> unittest

The auto-complete for VS-Code, when I try and import file1.py functions into file2.py auto-completes the import to:当我尝试将file1.py函数导入file2.py时,VS-Code 的自动完成功能会自动完成导入到:

import classes.subfolder1.file1

instead of代替

import src.classes.subfolder1.file1

how do I change what VSCode sees as the top folder?如何更改 VSCode 视为顶级文件夹的内容?

Per the comments, adding a __init__.py file under the src directory fixed the issue.根据评论,在 src 目录下添加一个__init__.py文件解决了这个问题。 Thanks to Prince Roshan for the suggestion感谢肉山王子的建议

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

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