Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module Not Found Error: No module named config

Tags:

python-3.x

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'

like image 312
Uponn Avatar asked Dec 07 '19 16:12

Uponn


3 Answers

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
like image 113
Roshin Raphel Avatar answered Nov 16 '22 02:11

Roshin Raphel


Try adding current dir to PYTHONPATH. PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. This helped for me.

export PYTHONPATH=.
like image 8
ky_aaaa Avatar answered Nov 16 '22 03:11

ky_aaaa


Installing it worked for me: pip3 install config

like image 5
brendah nyaringita Avatar answered Nov 16 '22 03:11

brendah nyaringita