ModuleNotFoundError Exercise 25

More than a month ago I started with the Learn Python The Hardway course. Up till now everything went very well. However when doing Exercise 25, I got stuck. In the Exercise you need to define some functions in Atom and save it as a .py file. After that you have to run python in the terminal and import ex25. I did all of that, but I get the error: ModuleNotFoundError: No module named ‘ex25’. I searched on the internet on how to fix this error. I found something about putting the file in the same directory. Therefore I saved the file in


because that is the directory where python is located. That did indeed the job. However, if you have to save every file that you want to import in python in that same folder, it will get very messy. So, I tried to find another way to let it work. Then I found how to import a file from a directory in the directory where python is saved. That is, I created a folder in


which I called ‘LPTHW’:


In this folder I saved the file.and then typed

import LPTHW.ex25.

This finally worked. The python files can now be clearly arranged.

But I am still not totally satisfied. It seems like it should have worked in the first case. In the corresponding video the file is saved in the same directory as where all the other exercises were saved in my case that should be


However, in my case I get an error when I import this in python. Do you have any idea what the reason is of this error? Do I need to do something differently?

I enclosed a screenshot of what I get when I try to do the exercise in the terminal, where I saved the file and where python is located. I am sorry for the Dutch language, but I do not know how to get it in English. I hope you can help me with my problem.

Thank you in advance!

On your windows PowerShell go to the directory(folder) where you have your ex25 file

yours seems to be C:\Users\Eline\temp>

Then open the python interpreter:
C:\Users\Eline\temp> python

than type:

import ex25

note: import ex25 (without the .py extension at the end)
Ex: Wrong!!—> import

For example, I have my file saved on the directory(folder) lpthw

1 Like

Thank you so much!

I thought that to run python you had to go back to the user directory. But you can also run python when you are in another directory. This helped.

Thank you!

Correct, you can definitely run python when you are in another directory!


1 Like