Can't find __'main'__ module error

Hi team,
Course- Learn Python and Ethical Hacking from Scratch
Problem- I am working on the mac changer with the function built into it, but when I try to run the program in the terminal, I get the error message: /usr/bin/python: can’t find ‘main’ module in ‘mac_changer.py’. I have the code exactly as Zaid has it but I still get this error. Is there any fix to it?

Can you post the exact code that you are running?

Screen Shot 2020-06-21 at 8.26.53 PM

I don’t see any problem with the code, I executed the same code, and it ran fine. Are you executing it inside the Pycharm’s terminal? I suggest you run it in Kali’s terminal and see if it runs or not.

Every time I tried to run the code I used the Kali Linux Terminal, but it always gives me the same error

Screen Shot 2020-06-26 at 6.27.31 PM

Am I mistaken? It looks like the name of the project is “mac_changer.py” with a “mac_changer.py” file inside. Do you have a directory named “mac_changer.py” inside your PycharmProjects directory? If so, save the Python file to another location and try running it again.

(Look carefully at the top left of first screenshot.)

What do you mean by changing the directory? Is it just saving the python file to a different folder inside of the folder dedicated for Pycharm Projects?

Based on the first screenshot, it appears to me your Pycharm project is called “mac_changer.py”. Then you wrote the code and saved the python FILE with the same name. The PROJECT should be called mac_changer or whatever you want but with no “.py” extension.

Perhaps try creating a new project, naming it something else. Remember to not have .py in the name. Create a new Python file in that project, call it whatever you want, copy that code and paste it in the new file, save and run that new file. It should work.

Edit: name the Python file with a .py extension, just make sure the project name does NOT have the .py extension.

1 Like

I believe what’s happening is you are trying to run mac_changer.py in the terminal in the PycharmProjects directory/folder but there is no file in that directory. It seems that file you are trying to run is probably in a directory named mac_changer.py which is inside the PycharmProjects directory. Sorry, I’m having some trouble explaining this.

The path would look something like this -> /root/PycharmProjects/mac_changer.py/mac_changer.py

Notice in that path you would have a directory with a .py ending which should not be there. I hope this makes sense.

Thank you! The program now works and I can continue the course.

Great! I had so much trouble trying to explain it.