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?
Charles Duffy
300k43 gold badges442 silver badges498 bronze badges
-
2Please 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).Charles Duffy– Charles Duffy2016年07月05日 21:54:34 +00:00Commented Jul 5, 2016 at 21:54
-
i'm using python 3.4anonymous_user– anonymous_user2016年07月05日 21:57:44 +00:00Commented Jul 5, 2016 at 21:57
1 Answer 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
answered Jul 5, 2016 at 21:58
James Lin
26.8k40 gold badges145 silver badges251 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Charles Duffy
Is it still in the future as of 3.4? I thought this became part of the language proper with 3.0.
James Lin
well OP only commented it after I place my answer, so don't need the import absolute_import
anonymous_user
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
lang-py