0

I came up with the situation where I want to use 2 separate projects in tensorflow. The problem is that I use a (quite heavy loaded) virtual environment and I would like to keep using it. In those projects there are two folders named (not too surprisingly) utils. So, I guess a conflict occurs when I import from the second folder.

Possible solutions that I could think of:

  1. Create a new virtual environment or even better clone the existing one like in here I guess. Con is that it takes about 1.7GB and I am running out of space (but I could deal with that somehow if that's the best choice).
  2. Try to debug the conflicting cases using folder prefixes like instead of: from utils import label_map_util I could use from project2.utils import label_map_util. This seems to work but has the con that I must search every file for conflicting imports. Like inside label_map_util.py where a similar import crashes (there are various folders in the project).

Is there any better solution? Am I missing something obvious here?

Also (I am fairly new to python) should this conflict be dealt automatically by python? I mean when inside a module in a folder and trying to import another module existing in the same folder or subfolder shouldn't this get priority over modules in other parallel folders (possibly in other projects etc)?

Edit:

To make it more clear I have 2 projects say projectA and projectB meaning 2 folders with various subfolders, which both contains a folder named utils. projectA was running just fine before the installation of projectB.

When I installed projectB and tried to run a module in it it contained imports from utils folder. Like

from utils import label_map_util
from utils import visualization_utils as vis_util

etc. I am using pyCharm and my IDE did not recognized the import as valid. I tried to debug it in interactive mode and my conclusions were:

  • There is a label_map_util.py module in folder utils in projectB folder.
  • For some reason import tries to find this module in projectA. So, when there is no module with that name it complains giving error:

    ImportError: cannot import name 'label_map_util'

  • in that sense import utils works fine but imports the wrong module (from projectA).

Eypros
  • 5,370
  • 6
  • 42
  • 75

0 Answers0