microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.53k stars 675 forks source link

reportMissingImports : Even if the module is successfully installed, a warning will still be displayed in the Error List window #7068

Open linette-zyy opened 2 years ago

linette-zyy commented 2 years ago

Environment image

Steps to Reproduce 1.Create a Flask Web Project. 2.Click Create virtual environment( Make sure Flask was successfully installed ). image 3.Reload the Project.

Expected behavior After Flask is successfully installed, no errors or warnings will be displayed.

Actual behavior image

Pylance Output info

Info: (11928) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (11928) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: Un-registering request handler for f75843bf-a321-48d6-a068-5f855d760690 failed.
Error: (11928) Error reading settings: TypeError: Cannot read properties of undefined (reading 'variableTypes')
Info: (11928) No configuration file found.
Info: (11928) No pyproject.toml file found.
Info: (11928) Setting pythonPath for service "FlaskWebProject7": "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe"
Warning: (11928) stubPath C:\Users\wangjun\source\repos\FlaskWebProject7\FlaskWebProject7\typings is not a valid directory.
Info: (11928) Assuming Python version 3.9
Info: (11928) Assuming Python platform Windows
Info: (11928) Searching for source files
Info: (11928) Found 3 source files
Info: (11928) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (11928) Background analysis(1) started
Info: (11928) Searching for source files
Info: (11928) Auto-excluding C:\Users\wangjun\source\repos\FlaskWebProject7\FlaskWebProject7\env
Info: (11928) Found 3 source files
Info: (8788) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (8788) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: (8788) No pyproject.toml file found.
Warning: (8788) stubPath typings is not a valid directory.
Info: (8788) Assuming Python platform Windows
Info: (8788) Searching for source files
Info: (8788) No source files found.
Info: (8788) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (8788) Background analysis(1) started
Info: (15044) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (15044) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: (15044) No pyproject.toml file found.
Warning: (15044) stubPath typings is not a valid directory.
Info: (15044) Assuming Python platform Windows
Info: (15044) Searching for source files
Info: (15044) No source files found.
Info: (15044) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (15044) Background analysis(1) started
Info: (5832) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (5832) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: (7592) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (7592) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: (7592) No pyproject.toml file found.
Warning: (7592) stubPath typings is not a valid directory.
Info: (7592) Assuming Python platform Windows
Info: (7592) Searching for source files
Info: (7592) No source files found.
Info: (7592) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (7592) Background analysis(1) started
Info: (4564) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (4564) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: (4564) No pyproject.toml file found.
Warning: (4564) stubPath typings is not a valid directory.
Info: (4564) Assuming Python platform Windows
Info: (4564) Searching for source files
Info: (4564) No source files found.
Info: (4564) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (4564) Background analysis(1) started
Info: (6244) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (6244) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: (6244) No pyproject.toml file found.
Warning: (6244) stubPath typings is not a valid directory.
Info: (6244) Assuming Python platform Windows
Info: (6244) Searching for source files
Info: (6244) No source files found.
Info: (6244) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (6244) Background analysis(1) started
Info: (14756) Pylance language server 2022.6.30 (pyright 212d1465) starting
Info: (14756) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Log: Notebook support: Legacy
Info: (14756) No pyproject.toml file found.
Warning: (14756) stubPath typings is not a valid directory.
Info: (14756) Assuming Python platform Windows
Info: (14756) Searching for source files
Info: (14756) No source files found.
Info: (14756) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (14756) Background analysis(1) started
linette-zyy commented 2 years ago

https://github.com/microsoft/PTVS/issues/6713 today's build is vs 2022 Preview 4, but it doesn't be fixed

excubo-jg commented 2 years ago

I think the recent comments on the closed issue https://github.com/microsoft/PTVS/issues/6713 also relate to this. Something seems to break once projects use flask which causes quite annoying erroneous knock-on warnings and falsely flagging modules and variables as being unused. The latter problem seems to go away once VS is restarted.

earnshaw commented 1 year ago

I am also getting the same issues - and I'm not even using flask. Be good to get this fixed as its annoying to keep seeing:

image

This was in version of 17.4.1 of Visual Studio Professional

earnshaw commented 1 year ago

Still a problem at 17.4.3 of Visual Studio Pro.

excubo-jg commented 1 year ago

I agree the problem is not limited to projects using flask. Probably related to https://github.com/microsoft/PTVS/issues/7274 as the "X could not be resolved" warnings are not reported when the CLI-version of pyright is run on the project.

axelande commented 1 year ago

Still a problem at 17.4.4 of Visual Studio

earnshaw commented 1 year ago

Whats the betting that it won't be fixed in the next version.

supershopping commented 1 year ago

Still having issue on Version 17.5.3.

flexorx commented 1 year ago

An issue on a fresh environment and newest VS-2022 (17.5.5). Works well in VS-2019; works in Version 17.6.0 Preview 6.0.

StellaHuang95 commented 1 year ago

@bschnurr This seems to still repro in the recent versions, shall we re-open it?

judej commented 1 year ago

We are still getting reports of this issue

bschnurr commented 10 months ago

I see this fixed in latest. it should be in the newest dogfood build

axelande commented 10 months ago

What do you mean with the newest dogfood build? When I tried with an updated version I got redirected here instead of my venv (for a few packages that was in pylance, for the other I get no redirect/help but the missing import underline is gone :)):

image

Could it be some issue with my .pyproj file? image

(All python files are in the first ItemGroup and there are no "python interpreter paths" defined in that ItemGroup)

Microsoft Visual Studio Community 2022 Version 17.8.5 VisualStudio.17.Release/17.8.5+34511.84 Microsoft .NET Framework Version 4.8.04084

Installed Version: Community

Visual C++ 2022 00482-90000-00000-AA553 Microsoft Visual C++ 2022

ASP.NET and Web Tools 17.8.358.6298 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.8.358.6298 Azure App Service Tools v3.0.0

C# Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Cookiecutter 17.0.23262.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.8.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Python - Profiling support 17.0.23262.1 Profiling support for Python projects.

Python - VC Project Support 17.0.23055.1 Provides support for launching C++ projects with Python debugging enabled.

Python with Pylance 17.0.23262.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Visual Basic Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

bschnurr commented 10 months ago

Preview 1 build image

axelande commented 9 months ago

Still the same problem for me with Pylance 17.0.24026.1: I think that the problem is related to paths in the .pyproj file.

I've played around and created a new project, which works great.

This is basically the folder structure that I'm working with:

my_project
- code
- - pythoncode
- - - folder_a
- - - - file_a.py
- msvc
- - python_proj
- - - python_proj.pyproj
- venv

Very complicated but it has it reasons...

In the python_proj.pyproj I have (among a lot of others):

 ....
    <ProjectHome>..\..\code\</ProjectHome>
    <SearchPath>..\</SearchPath>
      ...
    <InterpreterId>MSBuild|venv|$(MSBuildProjectFullPath)</InterpreterId>
  <ItemGroup>
   <Content Include="pythoncode\folder_a\file_a.py" />
  </ItemGroup>
  <ItemGroup>
    <Interpreter Include="..\venv\">
      <Id>venv</Id>
      <Version>3.11.1</Version>
      <Description>venv (Python 3.11.1) my_project</Description>
      <InterpreterPath>Scripts\python.exe</InterpreterPath>
      <WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
      <LibraryPath>Lib\</LibraryPath>
      <PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
      <Architecture>x64</Architecture>
    </Interpreter>
  </ItemGroup>

The code works and I can run it, debug it etc. etc. but pylance doesn't find the venv with this structure, where does it search or how can I specify where it should search for a venv?

StellaHuang95 commented 9 months ago

@bschnurr Looks like it still repros, so I just reopened the issue.

axelande commented 9 months ago

Anything I can do to help fix this issue? (Or change paths in my .pyproj file to help the Intellisense?)

fmelfa commented 9 months ago

I just installed Microsoft Visual Studio Professional 2022 update to Version 17.8.7 and it resolve the issue Python - Django support 17.0.23262.1 Python - Profiling support 17.0.23262.1 Python - VC Project Support 17.0.23055.1 Python with Pylance 17.0.23262.1 Visual Studio IntelliCode 2.2

image

axelande commented 8 months ago

Any news while working with a complex folder structure?

axelande commented 4 months ago

Is there any possibility to tell the intellisense where to look for the venv?

bschnurr commented 1 month ago

appears to be fixed Image

axelande commented 1 month ago

I tried to get the latest preview version, however still the same issue. @bschnurr can you try to set up a project with the folder structure like I described in the post from 14 feb and see if that works for you?

axelande commented 1 month ago

I've pinpointed that I can't get the intellisense to work in VisualStudio due to my folder structure, is there any way to help the intellisense to find the correct Python environment? The VisualStudio runtime understand it but not the intellisense.