vscode import error for python module

后端 未结 9 1986
栀梦
栀梦 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条回答
  •  心在旅途
    2020-12-02 21:10

    Since this is a VScode question I could add what my answer was.

    We are running many Python Django backends in a backends folder like so:

    +projectBackends
        -oneService
        -twoService
        -threeService
    

    And so in my project folder in VScode I just opened the projectBackends folder, because this would then give me all the services underneath it all at once. Seemed clear and simple. But then all the linting gets done from the root folder which is projectBackends, and not from the root folder of each service:

    from oneService.module1 import view
    

    gave and import error, where if I put

    from projectBackends.oneService.module1 import view
    

    I got no error, but then the microservice would not work.

    So in the end I just added a folder for every microservice in my workspace like:

    +oneService
    +twoService
    +threeService
    

    Which solved all the import errors for the independant microservices

提交回复
热议问题