3

I am trying to import a .py from a different folder in my project but got the Module not found error. Please help.

this is my project tree.

PROJECT_name
+trnsvr
|
\--trn_db.py

+websvr
|
\--instance
   |
   --config.py
\--app
   |
   --__init__.py

in trn_db.py I did import websvr.instance.config as conf

but got the ModuleNotFoundError as follow.

ModuleNotFoundError: No module named 'websvr'

how do I resolve this? thank you

Narae
  • 59
  • 1
  • 10

2 Answers2

0

Try copying this into trn_db.py. I got this from here.

import sys
sys.path.insert(1, '../websvr/instance/')
import config as conf
DavideBrex
  • 2,374
  • 1
  • 10
  • 23
0

Try to specify the file path... c:/MicrosoftVSCode/randomthings1.py. When not right next to it (in the same folder), python has sometimes problems accessing files. Also, make sure antimalware software isn't blocking python's access. <- My case

scraptechguy
  • 69
  • 10