Reputation: 239
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'
Upvotes: 20
Views: 116935
Reputation: 3379
Just add an empty file with the name __init__.py
in the config
folder of the project.
Upvotes: 0
Reputation: 1
after pip3 install config:
from config import config
ImportError: cannot import name 'config' from 'config' (C:\Python310\lib\site-packages\config\__init__.py)
Upvotes: 0
Reputation: 3527
If you are using Python 3, run the following to install config
.
sudo pip3 install config
Upvotes: 1
Reputation: 320
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=.
Upvotes: 10
Reputation: 2689
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
Upvotes: 12