2

抱歉,如果这似乎是之前几个问题的重复,但到目前为止这些问题都没有帮助我:-/

我编写了一个 Flask 应用程序,我试图在 mod_wsgi 和 apache2 下部署它。

我得到以下信息ImportError

[Tue Apr 23 23:46:56 2013] [info] Server built: Dec  9 2012 18:57:18
[Tue Apr 23 23:46:56 2013] [info] mod_wsgi (pid=7445): Initializing Python.
[Tue Apr 23 23:46:56 2013] [info] mod_wsgi (pid=7445): Attach interpreter ''.
[Tue Apr 23 23:47:10 2013] [info] [client 127.0.0.1] mod_wsgi (pid=7443, process='foo.com', application=''): Loading WSGI script '/Users/admin/Sites/p4p/p4p_jsapp/pfp/pfp.wsgi'.
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7443): Target WSGI script '/Users/admin/Sites/p4p/p4p_jsapp/pfp/pfp.wsgi' cannot be loaded as Python module.
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7443): Exception occurred processing WSGI script '/Users/admin/Sites/p4p/p4p_jsapp/pfp/pfp.wsgi'.
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1]   File "/Users/admin/Sites/p4p/p4p_jsapp/pfp/pfp.wsgi", line 7, in <module>
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1]     from PfpServer import app as application
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1]   File "/Users/admin/Sites/p4p/p4p_jsapp/pfp/PfpServer.py", line 4, in <module>
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1]     import pandas as pd
[Tue Apr 23 23:47:10 2013] [error] [client 127.0.0.1] ImportError: No module named pandas

阿帕奇配置:

<VirtualHost *:80>

    ServerName  www.foo.com
    ServerAlias foo.com

    DocumentRoot /Users/admin/Sites/p4p/p4p_jsapp/www

    <Directory /Users/admin/Sites/p4p/p4p_jsapp/www>
    Order allow,deny
    Allow from all
    </Directory>

    WSGIDaemonProcess foo.com user=admin processes=2 threads=15 display-name=%{GROUP}
    WSGIProcessGroup foo.com

    WSGIScriptAlias / /Users/admin/Sites/p4p/p4p_jsapp/pfp/pfp.wsgi

    <Directory /Users/admin/Sites/p4p/p4p_jsapp/pfp>
    WSGIProcessGroup foo.com
    WSGIApplicationGroup %{GLOBAL}
    Order allow,deny
    Allow from all
    </Directory>

</VirtualHost> 

pfp.wsgi:

import sys

activate_this = '/Users/admin/Sites/p4p/p4p_jsapp/foo/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

sys.path.append('/Users/admin/Sites/p4p/p4p_jsapp/pfp')
from PfpServer import app as application

PfPServer.py:

import numpy as np
import pandas as pd
import ujson
from flask import Flask, Response, request, render_template
import traceback

app = Flask(__name__)

# ...

我曾尝试使用和不使用 virtualenv 来查看是否有帮助,但无论如何我都会遇到同样的错误。这里有什么问题?

编辑:为了完全清楚,我安装了 pandas 并且应用程序在调试器中本地运行良好

edit2:好的,解决方案在 sys.path 中 - 我已经安装了最新的 pandas RC,它位于非标准路径上,这就是为什么当我单独添加 std 站点包路径时它不起作用的原因:

sys.path.append('/Users/admin/dev/pandas/pandas-0.11.0rc1')
sys.path.append('/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages')

...工作 - 谢谢大家!

4

1 回答 1

-1

我的猜测是 apache 运行的 Python 与您用于测试应用程序的 Python 不同。

于 2013-04-23T23:13:54.527 回答