0

I am using VS Code to code in Python. Every time I try to import a Python module from a relative path, there is the above error. There is nothing wrong with the folder path. I have tried the relative path import in Pycharm and it works fine.

I read a few posts about a similar bug occurring in VScode about a year ago. Does anyone know the solution?

from folder1.python1 import hello
hello() # Simply should print "hello"


ModuleNotFoundError: No module named 'folder1'

The path folder1.python1 is automatically intellisensed by the way.

ngong123
  • 63
  • 5
  • check the path of vscode it should be in the folder where your .py file is. – user13966865 Jul 21 '20 at 16:07
  • can you share the "few posts about a similar bug occurring in VScode about a year ago"? – adamgy Jul 21 '20 at 16:08
  • https://github.com/microsoft/vscode/issues/79612, https://github.com/microsoft/vscode-python/issues/5660, https://stackoverflow.com/questions/59702230/how-to-correctly-import-a-python-module-in-vs-code (Solution about Pylint - Don't think directly related to path error) – ngong123 Jul 21 '20 at 16:10
  • Yeah the relative path is shown as folder1.python1, and works when I import a library but not .py modules. – ngong123 Jul 21 '20 at 16:15
  • it works. try updating vs code and run command from path_to_root_file>python caller.py – user13966865 Jul 21 '20 at 16:36
  • Yup I'm not using the newest version... that might help. In addition, could you elaborate what you mean by path_to_root_file>python caller.py? I haven't used that before. – ngong123 Jul 21 '20 at 16:58

0 Answers0