1

I have a project where my main folder is called "trainer". all of my code is in this folder.

trainer
---main.py
---param_tuner.py

My main.py for now consists of just one import

from trainer.param_tuner import tune

When run my program in pycharm, the import works fine. However when i run it from the command line it doesn't work. I get an error

ModuleNotFoundError: No module named 'trainer'
  • Does this answer your question? [Can't import my own modules in Python](https://stackoverflow.com/questions/9383014/cant-import-my-own-modules-in-python) – kip Mar 08 '20 at 02:53
  • 1
    How are you running it from the command line? Under which folder did you run it? – Gino Mempin Mar 08 '20 at 03:54
  • you may run code from different folder and then it search modules in different folder. You may have to get absolute path to folder with your script `os.pathdirname(os.path.abspath(sys.argv[0]))` and add to list `sys.path` before importing. Python uses folders from `sys.path` to search your module. BTW: check `print( os.getcwd() )` to see Current Working Directory (CWD) – furas Mar 08 '20 at 04:11

0 Answers0