PTVS
PTVS copied to clipboard
Unexpected error in python development: unresolved import '__main__'
This issue has been moved from a ticket on Developer Community.
When developing a modular python code (with actual custom modules imported) you can use import __main__ from a module to extract data from main.
The __main__ keyword should not be interpreted by Visual Studio as a module name
That's not what it's actually happening: it's showing a warning in the "Error list" view which says: unresolved import '__main__'
Original Comments
Feedback Bot on 4/13/2022, 10:57 PM:
(private comment, text removed)
Bill Schnurr [MSFT] on 4/15/2022, 00:03 PM:
(private comment, text removed)
Dario Panico on 4/19/2022, 00:18 AM:
(private comment, text removed)
Bill Schnurr [MSFT] on 4/20/2022, 11:06 AM:
(private comment, text removed)
Dario Panico on 4/21/2022, 00:36 AM:
(private comment, text removed)
Bill Schnurr [MSFT] on 4/21/2022, 02:43 PM:
(private comment, text removed)
Bill Schnurr [MSFT] on 4/21/2022, 03:04 PM:
(private comment, text removed)
Original Solutions
(no solutions)
@dariopnc opened it originally: I'm here for further needs
Note that __main__
is not a keyword - it is, indeed, a module name, it just happens to be the name used by Python itself for the main module when registering it in sys.modules
.
Either way, code completion should probably consider it "always present", but resolving members might be trickier. When there's a project, we know the startup file, so we could map it to that.