1

I am creating a python module. To test it i put the file in the same directory and then wrote the code

import mymodule
mymodule.dofunction

python then said >>>no module named mymodule but they are in the same directory.

EdChum
  • 376,765
  • 198
  • 813
  • 562
MagikCow
  • 863
  • 8
  • 13

1 Answers1

0

Adapting from previous answer here. Explicitly state that you want to use the current directory.

Also, consider that you need an "__init__.py" file in each directory you are importing from.

import os, sys
lib_path = os.path.abspath('.')
sys.path.append(lib_path)

import mymodule

More information on the import system here.

Community
  • 1
  • 1
M. K. Hunter
  • 1,778
  • 3
  • 21
  • 27