I have a Python project having the following hierarchy:
- product_recommender_sys
- data
- dataset.csv
- public
- __init__.py
- startup.py
- src
- __init__.py
- recommender.py
I am trying to import the recommender.py module in startup.py.
Following is the code:
import sys
sys.path.insert(0, '/home/user1/product_recommender_sys/src')
print sys.path
from product_recommender_sys.src import recommender
recommender.recommend()
I have included __init__.py file and added the respective folders to sys.path. Also, the same import statement works perfectly fine on the Python interpreter, but fails inside the script. How can I get the import to work inside the script?
Andrew T.
4,7078 gold badges48 silver badges69 bronze badges
1 Answer 1
I found the issue. The startup.py module was not getting compiled since it was not being imported.
First compiling the script solves the problem.
python -m compileall product_recommender_sys/public/startup.py
Sign up to request clarification or add additional context in comments.
Comments
lang-py
sys.path.insert(0, '/home/user1/product_recommender_sys')Since this is the root folder of the module.__init__.pyfile in both sub-directories?