0

I am trying to import packages in python . Below mentioned is my folder structure

MainFolder
      |config| locator|logs|page|tests

Each folder has __init__.py file . tests folder has test.py. Now , inside test.py i am trying to import files from folders - config| locator|logs
However python is not recognizing them as package. If I place them under C:\Python27\Lib then I am able to import.

I tried adding sys.path.append(os.path.abspath("/ MainFolder/<folder name>")) before importing but it is not working. How do I import them ?

pajaja
  • 2,164
  • 4
  • 25
  • 33
Sachetan
  • 89
  • 4
  • 13
  • 1
    You will need to add the location of the desired modules to your python path. From within your test script you can do that by appending the path to the each dependency you need. Note howerver that other python scripts will not benefit from this. https://stackoverflow.com/questions/15109548/set-pythonpath-before-import-statements As a more permanent fix, you could try adding those dependencies to your PYTHONPATH. How to do that depends on which OS you are running. – BoboDarph Jun 29 '17 at 10:30
  • Thanks for the info. I am using windows. code_byter's solution worked for me. – Sachetan Jun 29 '17 at 15:04

1 Answers1

3

Please try the solution:

import sys
sys.path.insert(0, '/path/to/application/app/folder')

from Importing files from different folder in Python

hridayns
  • 697
  • 8
  • 16