10

I have several Python projects and they all have a conf package:

/some_folder/project_1/
  conf/
    __init__.py
    some_source_file.py

/another_folder/project_2/
  conf/
    __init__.py
    another_source_file.py

For each project, I have created a .pth file in the site-packages folder with this contents:

.../site-packages/project_1.pth:
import sys; sys.path.append('/some_folder/project_1/')

.../site-packages/project_2.pth:
import sys; sys.path.append('/another_folder/project_2/')

I can access modules in /some_folder/project_1/:

import conf.some_source_file

but not the modules in /another_folder/project_2/:

import conf.another_source_file
AttributeError: 'module' object has no attribute 'another_source_file'

It looks as if python only searches the first conf path underneath any folders in sys.path. Is there a way to fix that?

informatik01
  • 15,636
  • 10
  • 72
  • 102
ssc
  • 8,999
  • 8
  • 57
  • 89
  • Possible duplicate of [Python : importing different module with same name](http://stackoverflow.com/questions/32884206/python-importing-different-module-with-same-name) – luator Nov 07 '16 at 08:10

1 Answers1

9

No. You will need to either rename one of them or turn the project directory into a package and import via that.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
  • 1
    correct. i've actually been doing that all along and now I realize the problem does not seem to be with python itself, but with the mod_wsgi apache module in whose context the second project is running. that's a whole different story of course, so I've posted a new question: http://stackoverflow.com/questions/6631826/mod-wsgi-import-python-modules-with-the-same-name – ssc Jul 09 '11 at 00:13