ModuleNotFoundError: No module named

Given a directory layout (just for example):


On my local machine import works:

from bar.quux import my_function

But why do I get ModuleNotFoundError: No module named "bar" on Pythonanywhere with the same code and folders structure? To make the import working on Pythonanywhere I have to change manually the code to: from quux import my_function

there should be empty file in bar dir

Also, take a look at

I added file in bar dir. Nothing changed. Import works on a local machine, but cloned to Pythonanywhere project import does not work. While folders structure and files are the same.

Why my subfolder does not see anything outside? I can not import anything from subfolder. It looks like the subfolder 'thinks' that it is the main project folder.

UPD: Each folder in the project thinks that it is the root folder and does not see anything outside. So I can not use any subfolders in my project on Pythonanywhere.

Adding /home/<my_username>/<my_project>/ to the sys.path does not help.

Do you have /home/Aleksey/my_project/bar on the sys.path before /home/Aleksey/my_project/?

print('\n'.join(sys.path)) output:


when running a file inside project's subfolder:

from my_project import spameggs


Traceback (most recent call last):
  File "/home/Aleksey/my_project/foobar/", line 9, in <module>
    from my_project import spameggs
ModuleNotFoundError: No module named 'my_project'

If /home/Aleksey/my_project is on the python path, then you cannot import my_project - Python looks inside directories that are on sys.path, not at those directories.