vscode import error for python module

后端 未结 9 1972
栀梦
栀梦 2020-12-02 20:26

I am trying to do an import in python from one directory level up.

import sys

sys.path.append(\'..\')
from cn_modules import exception

I g

9条回答
  •  Happy的楠姐
    2020-12-02 21:12

    I tried to add this in my launch.json, then it works!

    "env": {"PYTHONPATH": "${workspaceRoot}"}
    

    below is my launch.json

            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {"PYTHONPATH": "${workspaceRoot}"},
            "console": "integratedTerminal"
    

    wish it can help u! :)

提交回复
热议问题