0

I have a module called my_module.py which is under the directory test/my_modules/my_module.py.

When I am trying to import that module in a different module using:

from test.my_modules.my_module import something

everything seems to be OK when running the code from PyCharm but when running the code outside PyCharm I get the following error:

ModuleNotFoundError: No module named 'test'

PS: Using Python 3.6 so __init__.py shouldn't be required in every module.

Tokyo
  • 753
  • 1
  • 10
  • 25
  • https://stackoverflow.com/questions/54955891/how-pycharm-imports-differently-than-system-command-prompt-windows/55083046#55083046 – CristiFati Jun 04 '19 at 15:54

1 Answers1

0

The working directory of PyCharm and the one where you are running the code outside of PyCharm are different. Hence, it does not find the module test anymore.

You need to change the relative path, where you want to import it from or add the folder, where the module test is located to your PYTHONPATH environmental variable, so that Python can find it.

LaurinO
  • 136
  • 6