问题
I have the following project structure:
Project
- GUI
- ...Modules
- Data
- Database
- ...Modules
- Files
- ...Modules
- Utilities
- ...Modules
And I am trying to do some imports over package borders, for example:
in the file(Module) Project.Database.dbdriver
I try to import Project.Utilities.Conversions
. If I use a fully specified import like import Project.Utilities.Conversions
this fails, it works with import Utilities.Conversions
, i.e. I can not specify more off the path than those part that differ. However I would like to use fully specified paths, one reason beeing that pydev in eclipse likes them better (otherwise it shows me an error), the second reason is I find it confusing not to do so.
I have stumbled over this but think it is wrong/not needed here How do I create a namespace package in Python?
Question: how can I use fully specified includes when crossing subbranches in a package structure?
回答1:
The fully specified import failed because the current working directory of python(or jython) was set to Project. you can:
add the parent directory of Project to your python lib
import sys
sys.path.append('/parent/of/project')
or just change the working directory of jython to the parent of Project in the debug settings.(I don't know how to do it because I don't use pydev.)
来源:https://stackoverflow.com/questions/11047086/python-full-path-import-not-working-across-branches-in-package-tree