0
import sys
import os


module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
    sys.path.append(module_path+"E:\\myfolder")

import myfile

Error:

[ModuleNotFoundError: No module named 'myfile']
martineau
  • 112,593
  • 23
  • 157
  • 280
Ali Nassar
  • 17
  • 4

1 Answers1

0

I think you're wrong at the sys.path.append(module_path+"E:\\myfolder") statement. Because the module path is now the absolute path, You don't need E: prefix.

Try again with:

sys.path.append(module_path+"\\myfolder")

You can check your paths by print(sys.path). It will print all paths that it's looking for the module

leminhnguyen
  • 1,062
  • 2
  • 8
  • 17
  • Hi and thank you for your help.I tried sys.path and put it in sys.append.append(). Do i put the mail file path or myfile path? I put the myfile path is this right ? – Ali Nassar Jun 20 '20 at 18:45
  • For info the two files are on anaconda jupyter platform. – Ali Nassar Jun 20 '20 at 18:48
  • @AliNassar No, You just need to put the folder path where contains your modules, in this case the folder containing `myfile` module. I guess you have `myfile.py` inside `myfolder`. I'm right ??? – leminhnguyen Jun 21 '20 at 02:14