sorry for cross-posting, i asked the same question at
http://stackoverflow.com/questions/6631826/mod-wsgi-import-python-modules-with-the-same-name,
but as i am unsure how many mod_wsgi experts are watching SO, i ask
here again.
I have two python projects and both have a conf package:
/some_folder/project_1/
some_source_file.py
conf/
__init__.py
some_conf_file.py
/another_folder/project_2/
another_source_file.py
conf/
__init__.py
another_conf_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/')
However, Python seems to only search the first subfolder it
encounters in any folders in sys.path for modules that are to be
imported, so the setup above only works for project_1:
this works: from conf import some_conf_file
this doesn't: from conf import another_conf_file
In order to fix this, I have turned project_1 and project_2 into
python packages and added a symlink in either, so I can access both
conf packages in a fully qualified fashion:
/some_folder/project_1/
__init__.py
project_1 <-- symlink to .
some_source_file.py
conf/
__init__.py
some_conf_file.py
/another_folder/project_2/
__init__.py
project_2 <-- symlink to .
another_source_file.py
conf/
__init__.py
another_conf_file.py
In an ordinary python script, I can now import modules from both conf
packages:
import project_1.conf.some_source_file
import project_2.conf.another_source_file
However, the second project is part of a WSGI application using the
mod_wsgi Apache module.
The wsgi 'start file' (i.e. the one with a wsgi suffix referenced in
the WSGIScriptAlias statement in the Apache config file for my virtual
server) successfully imports /another_folder/project_2/
another_source_file which in turn is supposed to import project_2/conf/
another_conf_file.py - and that import fails with
ImportError: No module named conf.another_source_file
/another_folder/project_2/ is in sys.path as printed out from
another_conf_file.py and the fact that the error message says
conf.another_source_file and not project_2.conf.another_source_file
leads me to believe that the python interpreter does actually find
project_2, but not project_2/conf.
Even more confusing is the fact that the same problem occurs when I
rename project_2/conf to project_2/conf_2.
I even tried using another subfolder project_2 instead of the symlink,
but I just can't seem to get this file to import.
Can anyone help me ?
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.