Well, the script is very simple. I have a file structure like this:
.
├── interface.py
├── pkg
│ ├── __init__.py
│ ├── mod1.py
│ ├── mod2.py
Here are my conditions:
- mod2 you need to import mod1.
- both interface.py and mod2 must be run independently as the main script. If you want, take the interface as an up-to-date program, and mod2 as an internal package tester.
So in Python 2, I just would have done import mod1
in mod2.py, and both python2 mod2.py
and python2 interface.py
would work as expected.
However, and this is the part that I less understand using Python 3.5.2 if I do import mod1
; then I can do it python3 mod2.py
, but it python3 interface.py
gives: ImportError: No module named 'mod1'
:(
, -, python 3 import pkg.mod1
. , , python3 interface.py
; python3 mod2.py
: ImportError: No module named 'pkg'
, : from. import mod1
from. import mod1
python3 interface.py
; mod2.py , SystemError: Parent module '' not loaded, cannot perform relative import
:( :(
"", , - python -m pkg.mod2
python -m pkg.mod2
. pkg
? , - , , -m? ?
. Python 2, Python 3.
: ( "") : https://gitlab.com/Akronix/test_python3_packages. , , , python2.
, :
: