The error message does not say that your use of relative import is wrong:
It says what you try to import is not in your current package. When you execute touch subpackage1/__init__.py
you make subpackage1
into a package. You cd into the directory, which means that for import you work from subpackage1, not your original package
. So
..subpackage2.moduleZ
says go up one directory, which is no longer in the package you are working in, although it would be in package
.