在 Visual Studio 代码中使用同一项目文件夹中的 python 包 [英] Use a python package in the same project folder in visual studio code

查看:31
本文介绍了在 Visual Studio 代码中使用同一项目文件夹中的 python 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目文件夹中创建了名为dto"的自定义包.但是它不能识别这个包和模块.

如何让我的 Visual Studio 代码找到它?

How can I make my visual studio code to find it?

在 Pycharm 中,如果我创建新包,它会自动检测.

In Pycharm, if I create new package, it automatically detects that.

  • 我在模拟包中执行了我的模拟器 .py 脚本.

推荐答案

我也遇到了同样的问题.似乎visual studio代码无法自动检测新的python包.它与 $PYTHONPATH 配置有关.我从 Visual Studio 代码文档中找到了官方参考.请查看此文档.

I have encountered the same problem. It seems visual studio code cannot automatically detect new python package. It has something to do with $PYTHONPATH configuration. I found an official reference from visual studio code documentation. Please have a look at this doc.

  1. 在你的项目中添加一个 dev.env 文件

PYTHONPATH=${workspaceFolder}:${PYTHONPATH}

  1. 在您的工作区中添加以下内容 settings.json 配置文件

"python.envFile": "${workspaceFolder}/dev.env"

这对我有用.调试器可以在新包中找到模块.希望这对您有所帮助.

This works for me. The debugger can find modules in the new package. Hopefully, this will help you.

这篇关于在 Visual Studio 代码中使用同一项目文件夹中的 python 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆