0

I've got a project tree like this:

../simple_top/
└── simple
    ├── __init__.py
    └── src
        ├── a.py
        ├── b.py
        └── __init__.py

a.py contains single function:

def a():pass

b.py tries to import that function:

from simple.src.a import a

When I try to run b.py from simple_top directory, I see the folowing error:

python3 simple/src/b.py 
Traceback (most recent call last):
  File "simple/src/b.py", line 1, in <module>
    from simple.src.a import a

ImportError: No module named 'simple'

Surprisingly, when I try to run the code from inside Pycharm environment (the working directory is set to simple_top), everything works fine. So why doesn't it run in the terminal? How to make it run in the terminal? It seems I'm missing something...

user1633361
  • 141
  • 9

1 Answers1

1

OK, actually, I found an answer to that question. I should run b.py this way:

python3 -m simple.src.b

Please refer to Relative imports in Python 3 Don't know why, but I didn't found it earlier...

user1633361
  • 141
  • 9
  • 1
    Worked for me, thanks! I tried setting the working directory using the env variable, but was still not able to run it using the python command. You should accept your own answer as the correct one! – Ivan Jul 04 '19 at 10:27