Unable to import Python module in Python script
Question: 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?


Answer: 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
    

