close

[Solved] How to fix “ImportError: No module named …” error in Python?

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error How to fix “ImportError: No module named …” error in Python? in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How How to fix “ImportError: No module named …” error in Python Error Occurs?

Today I get the following error How to fix “ImportError: No module named …” error in Python? in python.

How To Solve How to fix “ImportError: No module named …” error in Python Error ?

  1. How To Solve How to fix “ImportError: No module named …” error in Python Error ?

    To Solve How to fix “ImportError: No module named …” error in Python Error Do you have a file called __init__.py in the foo directory? If not then python won't recognise foo as a python package.

  2. How to fix “ImportError: No module named …” error in Python?

    To Solve How to fix “ImportError: No module named …” error in Python Error Do you have a file called __init__.py in the foo directory? If not then python won't recognise foo as a python package.

Solution 1

better fix than setting PYTHONPATH is to use python -m module.path

This will correctly set sys.path[0] and is a more reliable way to execute modules.

I have a quick writeup about this problem, as other answerers have mentioned the reason for this is python path/to/file.py puts path/to on the beginning of the PYTHONPATH (sys.path).

Solution 2

Do you have a file called __init__.py in the foo directory? If not then python won’t recognise foo as a python package.

See the section on packages in the python tutorial for more information.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment