Module Not Found Error: No module named config

Uponn

I'm trying to run my project from terminal but I keep on getting ModuleNotFoundError: No module named 'config'. The structure of my project is:

Project folder
   -config
      -settings.py
   -folder1
     -folder2
        -pythonfile.py

While in folder1/folder2/ I run the script --> python3 -m pythonfile.py but I get the No module named config. The Run button from PyCharm works like charm but I want to run the script from terminal. Also I've checked the sys.path and I've got the root path of the project /home/name/Desktop/Project and the /home/name/Desktop/Project/folder1/folder2/.

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/name/Desktop/Project/folder1/folder2/pythonfile.py", line 4, in <module>
    from config import settings as CONFIG
ModuleNotFoundError: No module named 'config'

Roshin Raphel

This issue occurs because, the path to the file app_one is not in the current working path, you have to add it to the path using sys.path.append function, Check this code :

import sys
sys.path.append('../../')
import config

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related