eorojas
eorojas

Reputation: 73

Import errors when moving from Python 3.6 to 3.7+, root-directory no longer legal from root_dir import

I've inherited code that gets the following

ModuleNotFoundError: No module named this_dir

when run on Python 3.7 or 3.8, but runs fine on Python 3.6.

this_dir contains:

To run:

python3.x mymain.py -p1 -p2 ...

Additionally, there is a completely independent module in a parallel directory that also has

from this_dir import far

Now, I would ignore this all except I want to use a feature introduced in Python 3.7.

Is there a way to define things in __init__.py to fix this?

Upvotes: 0

Views: 290

Answers (1)

eorojas
eorojas

Reputation: 73

Indeed, the problem is that the code modules have been pip installed in python3.6 making this_dir globally accessible in 3.6, but not in 3.7. This seems a categorically poor way of doing this to me, but ... I'm going to read up on name resolution because I'm surprised this is legal, but also to make sure there are no gotta's. If any of the more knowledge care to comment on the wisdom of developing against an installed module while it is installed I'm all ears. The cross dependency is clearly a problem. What you get when EEs are allowed to write code unsupervised.

Upvotes: 1

Related Questions