0

I have the below folder structure for my python project:

./SampleA/
   __init__.py
   company.py
./SampleB/
   __init__.py
   check.py

Now i am trying to import company.py module in my check.py module using the below command:

from SampleA import company

when i run the file i get the below error :

ModuleNotFoundError: No module named 'SampleA'

How to fix this ?

Torxed
  • 22,866
  • 14
  • 82
  • 131
SunilA
  • 513
  • 8
  • 19
  • @rdas - when i append the path , the vscode editor moves the all the import files to the top and sys.path.append is only after import commands. so import company could not import the module. – SunilA May 22 '20 at 08:08
  • Does [this](https://stackoverflow.com/a/61235118/8873120) answer your question? – RMPR May 22 '20 at 08:17
  • @RMPR - no it does not work for me. sys.path.append line of code comes after the import statement. So import happens before the path added to the path. – SunilA May 22 '20 at 08:27
  • There's no mention to `sys.path.append` in the answer I linked – RMPR May 22 '20 at 08:31

1 Answers1

0

You're Trying to Import sibling module and not child module. Say You're Folder structure is something like

-SampleB
 - __init__
 - check
 - SampleA

Then it will work. - Right way to import sibling packages follow this link

Krishna
  • 198
  • 2
  • 10