0

I have a directory called project set up like this:

Project

--directory:src--  
--directory:testscripts--  
--directory:config_files--  
RunPCS.py

and within src, it is set up as:

src

parse_files.py  
parse_json.py  
process_xml.py  
__init__.py

in RunPCS.py I have from src.parse_files import parse_files and from src.parse_json import parse_json

in parse_json.py I have from process_xml import process_xml (since they are in the same directory)

but i get the error no module named process_xml. does anyone know why this error shows up?

2
  • 2
    Please be specific about which version of Python -- the relative-import rules vary. See, ie. docs.python.org/2.5/whatsnew/pep-328.html -- introducing explicit relative-import syntax in 2.5 (which you probably should be using here). Commented Jul 5, 2016 at 21:54
  • i'm using python 3.4 Commented Jul 5, 2016 at 21:57

1 Answer 1

1

for the import statement, use

from .src.parse_files import parse_files
from .src.parse_json import parse_json

in your parse_json.py

from .process_xml import process_xml
Sign up to request clarification or add additional context in comments.

3 Comments

Is it still in the future as of 3.4? I thought this became part of the language proper with 3.0.
well OP only commented it after I place my answer, so don't need the import absolute_import
thanks for the answers. however when i used "from .src" it gives the error ' ' not loaded, cannot perform relative import. when i make the change "from .process_xml import process_xml" and use src instead of .src it fixes the issue however

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.