Issue
How do I import helpers in script.py ?
Python version : 3.6.8
directory structure :
main_folder
|
| folder1
| | folder2
| | | script.py
|
| helpers.py
script.py :
from helpers import markdown
command :
python3 folder1/folder2/script.py
error :
ModuleNotFoundError: No module named 'helpers'
Solution
You can add the following to the top of script.py
to correctly set the path.
import sys
import os
module_path = os.path.abspath(os.getcwd())
if module_path not in sys.path:
sys.path.append(module_path)
Keep the rest as is and it should work
Answered By - Hommes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.