Error importing pyw files #2741
Replies: 9 comments
-
I am facing the same issue in VS code, if two files are in the same folder. It should be able to import from one file to another. Am I missing something? |
Beta Was this translation helpful? Give feedback.
-
Is this in the root directory of your project, or is it in a subdirectory? If it's in a subdirectory, you will need to tell pylance that you want to use that subdirectory to resolve imports. You can do this by adding it to the "python.analysis.extraPaths" setting. Does that make the error go away? |
Beta Was this translation helpful? Give feedback.
-
No, because file in the root directory of project |
Beta Was this translation helpful? Give feedback.
-
Ah, I just realized that I misread your original bug report. I read it as "pyd" file, which is a binary library file. I have never heard of "pyw" files before. Pylance doesn't have any knowledge of this file extension. It doesn't attempt to resolve such files currently, so that explains the problem. |
Beta Was this translation helpful? Give feedback.
-
By default python installs two interpreter files, python.exe and pythonw.exe . Files with the extension .pyw are launched via pythonw.exe, the only difference of which is that it does not create a separate window, the script is, as it were, executed in the background. |
Beta Was this translation helpful? Give feedback.
-
Yes, I see this is a Windows-specific thing. This mechanism must be used rarely because this is the first time this has been reported in the 2+ years that pylance has been under development. It will take a bit of work to find all of the places where the pylance and pyright code assumes ".py" file extensions and extend it to support ".pyw" as well. This affects not only import resolution but many other pieces of functionality like auto-import suggestions and dynamic mapping between stub and source files. |
Beta Was this translation helpful? Give feedback.
-
Okay, thanks! I will be waiting for new versions) |
Beta Was this translation helpful? Give feedback.
-
Did you mean to close this? I presume you are interested in this feature still? I'll re-open. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How to reproduce the error
Pylance print:
Import "test9" could not be resolved
Full error info
Originally posted by @DaSh-More in #924 (comment)
Beta Was this translation helpful? Give feedback.
All reactions