When running gopy according to the docs and having multiple packages in the module where one imports the other, relative as well as absolute imports are used. Thereby, it becomes impossible to import the depending package.
Exemplary project structure:
mymod
|-- ecs
| `-- ecs.go
`-- model
`-- model.go
Where model imports ecs.
Running this command:
gopy pkg -output=out github.com/mlange-42/mymod
The generated code in model.py looks like this:
# ...
from ..mymod import _mymod
from ..mymod import go
os.chdir(cwd)
# to use this code in your end-user python file, import it as follows:
# from mymod import model
# and then refer to everything using model. prefix
# packages imported by this package listed below:
from mymod import ecs
# ...
Depending on where I start the REPL and how I try to import, I get either:
When running
gopy
according to the docs and having multiple packages in the module where one imports the other, relative as well as absolute imports are used. Thereby, it becomes impossible to import the depending package.Exemplary project structure:
Where
model
importsecs
.Running this command:
The generated code in
model.py
looks like this:Depending on where I start the REPL and how I try to import, I get either:
(Run from
out
, withfrom mymod import model
)or:
(Run from
mymod
, withfrom out.mymod import model
)Workaround
The only way I could get it to work (without editing generated Python files) is to run
gopy
withpackage-prefix
set to nothing:Then, running the Python REPL from
out
, it works:This is not obvious from the docs, and probably also not intendend. Possibly related to #245, #301, #302