Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97327

VSCode 1.39.x & Python 3.7.x: "ImportError: attempted relative import with no known parent package" - when started without debugging (CTRL+F5))

$
0
0
  • when running Python test from withing VS Code using CTRL+F5 I'm getting error message

    ImportError: attempted relative import with no known parent package

Error message text: "ImportError: attempted relative import with no known parent package"

  • when running Python test from VS Code terminal by using command line

    python test_HelloWorld.py

    I'm getting error message

    ValueError: attempted relative import beyong top-level package

Error Message: "ValueError: attempted relative import beyond top-level package"

Here is the project structure

Project structure

How to solve the subject issue(s) with minimal (code/project structure) change efforts?

TIA!

[Update]

I have got the following solution using sys.path correction:

The subject issue solution using sys.path correction

import sys
from pathlib import Path
sys.path[0] = str(Path(sys.path[0]).parent)

but I guess there still could be a more effective solution without source code corrections by using some (VS Code) settings or Python running context/environment settings (files)?


Viewing all articles
Browse latest Browse all 97327

Trending Articles