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
  • 119,623
  • 25
  • 170
  • 301
Ali Nassar
  • 17
  • 1
  • 6

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,518
  • 2
  • 13
  • 19
  • 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