beyond top level package error in relative import

后端 未结 13 2263
醉梦人生
醉梦人生 2020-11-22 12:50

It seems there are already quite some questions here about relative import in python 3, but after going through many of them I still didn\'t find the answer for my issue. s

相关标签:
13条回答
  • 2020-11-22 13:30

    Edit: 2020-05-08: Is seems the website I quoted is no longer controlled by the person who wrote the advice, so I'm removing the link to the site. Thanks for letting me know baxx.


    If someone's still struggling a bit after the great answers already provided, I found advice on a website that no longer is available.

    Essential quote from the site I mentioned:

    "The same can be specified programmatically in this way:

    import sys

    sys.path.append('..')

    Of course the code above must be written before the other import statement.

    It's pretty obvious that it has to be this way, thinking on it after the fact. I was trying to use the sys.path.append('..') in my tests, but ran into the issue posted by OP. By adding the import and sys.path defintion before my other imports, I was able to solve the problem.

    0 讨论(0)
提交回复
热议问题