简体   繁体   English

VSCode 未在 windows 的 WSL 模式下的工作区中设置 PYTHONPATH

[英]VSCode not setting PYTHONPATH in workspace in WSL mode in windows

I have a WSL (Ubuntu-20.04) and opening a VSCode in WSL mode.我有一个 WSL (Ubuntu-20.04) 并在 WSL 模式下打开一个 VSCode。 I am trying to create a project and folders inside them.我正在尝试在其中创建一个项目和文件夹。 I am not able to import the modules of the project.我无法导入项目的模块。 It is giving me "unable to import" pylint errors.它给了我“无法导入”的 pylint 错误。 Below is my folder structure下面是我的文件夹结构

my_project
  |
  |- src
    |
    |- logger_utils
      |
      |- logger.py
    |- driver.py
  |- test

Inside my driver.py , if I try to import a method as from src.logger_utils.logger import get_logger , pylint raises a error - Unable to import在我的driver.py中,如果我尝试from src.logger_utils.logger import get_logger方法,pylint 会引发错误 - Unable to import

This is happening only in WSL mode.这仅在 WSL 模式下发生。 But the same is working fine in normal mode.但在正常模式下同样可以正常工作。 Any fix/suggestions for this issue针对此问题的任何修复/建议

This is probably a PYTHONPATH issue.这可能是一个 PYTHONPATH 问题。 In your VScode settings for your workspace, add the following:在工作区的 VScode 设置中,添加以下内容:

"terminal.integrated.env.linux": {"PYTHONPATH": "${workspaceFolder}/src"},

You may need to restart VScode after as well.之后您可能还需要重新启动 VScode。

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

相关问题 在 git 跟踪的项目中处理 vscode 设置工作区 python.pythonPath - Dealing with vscode setting workspace python.pythonPath in git tracked project 尽管设置了 PYTHONPATH,但在 VSCode 中导入错误 - Import error in VSCode despite setting the PYTHONPATH 如何为 Vscode(在 Windows 上)中的所有工具设置 PYTHONPATH? - How to set PYTHONPATH for all tools in Vscode (on Windows)? WSL VSCode 调用 Windows Python 可执行 - WSL VSCode call Windows Python Executable 在Windows中为项目设置相对pythonpath(Visual Studio Code) - Setting relative pythonpath for project in Windows (Visual Studio Code) 在没有提升权限的情况下在Anaconda下的Windows上设置PYTHONPATH - Setting PYTHONPATH on Windows under Anaconda without elevated privileges 在vscode调试模式下,进入workspace根目录下的子文件夹? - In vscode debug mode, enter the subfolder of the root directory of the workspace? 尝试在 VSCode、Windows WSL2 上全局安装 autopep8 - Trying to get autopep8 installed globally on VSCode, Windows WSL2 无法在 linux 的 WSL windows 子系统中导入 rpy2、VSCode - Unable to import rpy2, VSCode in WSL windows subsytem for linux Pipenv未设置PYTHONPATH - Pipenv not setting PYTHONPATH
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM