mod_wsgi:导入同名的python模块

mod_wsgi:导入同名的python模块,python,import,mod-wsgi,Python,Import,Mod Wsgi,这是对的后续问题,但由于这两个问题有些不相关,因此最好提出一个新问题: 我有几个python项目,它们都有一个conf包: /some_folder/project_1/ conf/ __init__.py some_source_file.py /another_folder/project_2/ conf/ __init__.py another_source_file.py 对于每个项目,我在site packages文件夹中创建了一个.pth文

这是对的后续问题,但由于这两个问题有些不相关,因此最好提出一个新问题:

我有几个python项目,它们都有一个conf包:

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

/another_folder/project_2/
  conf/
    __init__.py
    another_source_file.py
对于每个项目,我在site packages文件夹中创建了一个.pth文件,其中包含以下内容:

.../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/')
现在,访问conf模块适用于/some_folder/project_1/:

import conf.some_source_file
但不适用于/other_文件夹/project_2/:

import conf.another_source_file
AttributeError: 'module' object has no attribute 'another_source_file'
这可能是因为python只搜索sys.path中任何文件夹下的第一个conf路径

因此,我将project_1和project_2转换为python包,并在其中添加了一个符号链接,因此我可以以完全限定的方式访问这两个conf包:

/some_folder/project_1/
  __init__.py
  project_1 <-- symlink to .
  conf/
    __init__.py
    some_source_file.py

/another_folder/project_2/
  __init__.py
  project_2 <-- symlink to .
  conf/
    __init__.py
    another_source_file.py
但是,当我尝试在使用mod_WSGI Apache模块的WSGI应用程序中执行相同操作时,第二个项目的导入失败。具体来说,wsgi“启动文件”,即在我的虚拟服务器的Apache配置文件中的WSGIScriptAlias语句中引用了wsgi后缀的文件,成功地在/other_folder/project_2/中导入了一个模块,该模块又导入了project_2/conf/other_source_file.py

第二次导入失败,尽管sys.path中有/other_folder/project_2/。WSGI应用程序正在守护程序模式下运行


如何对其进行排序?

FWIW,这是在mod_wsgi邮件列表中处理的,从内存中发现是由于存在同名的模块和包而导致的,并拾取了错误的模块和包。

FWIW,这是在mod_wsgi邮件列表中处理的,从内存中可以看出,这是由于存在同名的模块和包而导致的,并且拾取了错误的模块和包

import project_1.conf.some_source_file
import project_2.conf.another_source_file