аватар question@mail.ru · 01.01.1970 03:00

Importerror: Attempted Relative Import with No Known Parent Package Python

I have such a project structure

  --- Package1/code.py --- paccage2/ext.py  

how to import me variable from Ext.PY to Code.Py?

from ext import var - it does not work, says that there is no module Ext

from ..Paccakeage2.ext Import Var is also not The error is being issued: Importerror: Attempted Relative Import with No Known Parent Package

аватар answer@mail.ru · 01.01.1970 03:00

Everything works.

  1. in the files indicate Import and from without leading points:

       from  package2.Ext  import  var    

       from  ..package2.ext  import  var    
  2. you need to call from the folder of your_project here is the following command:

      Python -m package1.code 
  3. You can indicate the path to python completely, type usr/bin/python . It is important to indicate -m and the point . .py

    .

    So:

      Way_K_VAMICUMT & GT; python -m package1.code                                      

Latest

Similar