0

If I execute demo2.py it works fine, the problem is when I execute main.py

|myPackage |subPackage demo.py demo2.py main.py 

main.py

from ludikDriver.demo2 import demo2_print demo2_print() 

demo2.py

from demo import demoprint def demo2_print(): print("demo2") demoprint() demo2_print() 

demo.py

def demoprint(): print("demo") 

Error:No module named 'demo'

3 Answers 3

1

Just use relative imports as suggested in pep 328.

from .demo import demoprint 

You can do for the other package. Just as relative paths.

Sign up to request clarification or add additional context in comments.

2 Comments

but if I do this I can´t execute demo2.py alone. It is posible?
No because you say to python you need to import the following task before run the code. There are some hacky ways to accomplish this, but i didn't would suggest this.
1

Your modules need context of themselves. You should have the "__init__.py" file in subPackage and myPackage. Then your import should be relative:

from . import demo 

OR more in context of your example:

from .demo import demoprint 

Comments

0

Your error is associated with the top line in demo.py:

from demo import demoprint

There is no module named demo

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.