rsk82 rsk82 - 6 months ago 14
Python Question

"no module named..." when running this python code

I have no idea what causes this error, this is as simplest as I could get, yet SO gives me hint that my question does not meet their quality standards so I must post this longer intro.

#===
# my_script.py
import myModule

#===
# myModule\__init__.py
import sys
from my_def import *

class MyModule:
def __init__(self):
pass

#===
# myModule\my_def.py
def my_def():
pass

Traceback (most recent call last):
File "my_script.py", line 1, in <module>
import myModule
File "D:\test\myModule\__init__.py", line 2, in <module>
from my_def import *
ImportError: No module named 'my_def'

Answer

you can try this:

sys.path.append("path_of_script")