-1

I can't import a python file from different folder in visual studio code. I also tried to save a init.py file in my module but got the same error. I don't wanna use pythonPATH.

import my_module.shopping_cart

the error I get:

/python/sample codes/notebook.py", line 4, in <module>
import my_module.shopping_cart

ModuleNotFoundError: No module named 'my_module'

Yudhishthir Singh
  • 2,941
  • 2
  • 23
  • 42
Fetona
  • 34
  • 6
  • You could try to refer to [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – AJackTi Jun 01 '20 at 02:49
  • 1
    I checked that. that did not work – Fetona Jun 01 '20 at 03:20
  • what I did is, I saved the module folder in the parent folder that contains my notebook.py file and I get another error: – Fetona Jun 01 '20 at 03:21

1 Answers1

1

Give me an example. I just test in my machine with tree folder

C:.
├───child
├───---- child.py
├───parent
├───---- parent.py

In child.py

aaa = 1234
print aaa

In parent.py

import sys
sys.path.insert(1, '../child')
from child import aaa

print aaa

And result:

1234 # result from child.py
1234 # result from parent.py
AJackTi
  • 63
  • 2
  • 7