2012-11-05 88 views
3

我们正试图摆脱在mod_wsgi上工作的wsgi应用程序。我们在使用wsgiref.simple_server作为调试环境之前已经运行了它。现在,我们希望将它转移到使用Apache httpd集成在同一端口下加载静态文件,并提供更适合生产的环境。用mod_wsgi导入python模块

我们设立了这个样子的httpd.conf文件:

<VirtualHost *:80> 

    DocumentRoot /var/www/ 

    ErrorLog /var/www/log/error_log 

    LogLevel debug 

    WSGIScriptAlias /app /var/www/python/resource/rest.py 

    <Directory /var/www/python/> 
      Order allow,deny 
      Allow from all 
    </Directory> 

    <Directory /> 
      Order allow,deny 
      Allow from all 

      RewriteEngine On 
      # Some rewrites go here 

    </Directory> 

</VirtualHost> 

有了这个设置,我们就可以进入主应用程序文件,rest.py(http://myhost/app下),但任何进口模块(像from module1 import function其中module1与rest.py位于同一目录下)失败,出现ImportError

我怀疑这与必须设置某种环境变量有关,但我在主应用程序方法中添加了/var/www/pythonsys.path,它不起作用。任何帮助或指针与此将非常感激。

谢谢!

+0

重复的http://serverfault.com/questions/445636/error-importing-python-modules-in-mod-wsgi –

回答

6

是/ var/www/python或/ var/www/python/resource下的rest.py?据我所知,将此目录添加到sys.path应该工作。优选使用字符串常量如下:

sys.path.append(os.path.dirname(__file__)) 

即使您决定将来部署到其他位置,这也应该可以工作。

+0

好吧,一定会给这个旋风。当我可以的时候,我会更新。谢谢! –