VSCode 新建 Python 包/模块 Pylance 无法解析

问题描述:

利用 VSCode 写代码,在项目里新建一个 Python 包或者模块,然后在其他文件里正常导入这个包或者模块时出现:

Import "xxxx" could not be resolved Pylance (reportMissingImports)

也就是说 Pylance 此时无法解析我们新建的包,也无法跳转到这个包的源码。但是我们是按标准正常 import 的。


原因分析:

本项目在打开项目文件夹时,会弹出以下警告:

Unable to watch for file changes in this large workspace folder. Please follow the instructions link to resolve this issue.

也就是说文件监控的实际数目已超出当前设置值。因此 Pylance 无法解析新建的包或者模块。


解决方案:

其他博客介绍了如下方法:

  • 设置里搜索 Analysis: Extra Paths,添加包路径[1](#1)
  • launch.json 文件中把根目录加入[2](#2)"env": {"PYTHONPATH":"${workspaceFolder}"},

这些方法过于繁冗,不一定能解决问题,笔者建议以下方法:


  1. 解决Vscode无法解析导入"xxxxx"Pylance的问题 ↩︎

  2. vscode下的python模块导入 ↩︎

相关推荐
不知更鸟23 分钟前
前端报错:快速解决Django接口404问题
前端·python·django
4***721327 分钟前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
梁正雄39 分钟前
1、python基础语法
开发语言·python
ituff2 小时前
微软认证考试又免费了
后端·python·flask
梁正雄3 小时前
2、Python流程控制
开发语言·python
Eric.Lee20214 小时前
ubuntu 安装 Miniconda
linux·运维·python·ubuntu·miniconda
无心水4 小时前
【Python实战进阶】1、Python高手养成指南:四阶段突破法从入门到架构师
开发语言·python·django·matplotlib·gil·python实战进阶·python工程化实战进阶
李剑一4 小时前
Python学习笔记1
python
Salt_07287 小时前
DAY 19 数组的常见操作和形状
人工智能·python·机器学习
a***13147 小时前
vscode配置django环境并创建django项目(全图文操作)
vscode·django·sqlite