close

[Solved] VSCode ModuleNotFoundError: No module named X

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error VSCode ModuleNotFoundError: No module named X 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 VSCode ModuleNotFoundError: No module named X Error Occurs?

Today I get the following error VSCode ModuleNotFoundError: No module named X in Python.

How To Solve VSCode ModuleNotFoundError: No module named X Error ?

  1. How To Solve VSCode ModuleNotFoundError: No module named X Error ?

    To Solve VSCode ModuleNotFoundError: No module named X Error Make sure you are running from the package folder (not from package/module) if you want import module.calculations to work. You can also set the PYTHONPATH environment variable to the path to the package folder.

Solution 1

Make sure you are running from the package folder (not from package/module) if you want import module.calculations to work. You can also set the PYTHONPATH environment variable to the path to the package folder.

Solution 2


According to your description, I don’t have gotten enough information, but I think I can speculate there are two key points you haven’t been aware of.

  • The relative import be used only inside package (or module).Referring to python official documentation ModulesNote that relative imports are based on the name of the current module. Since the name of the main module is always __main__, modules intended for use as the main module of a Python application must always use absolute imports.Even if calculations.py is inside package, but you run it as ‘main module’, it does also not work.
  • The absolute import’s module (your own) should be located under the your current work directory (under the path which is in either sys.path or env PYTHONPATH)For the issue that it works fine in test, I think it depends on the directory where your ‘main module’ working, you should check it carefully.

You just need to address this two points, you will work out your problem.

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