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'
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
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=.
Installing it worked for me: pip3 install config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With