对不起,如果这似乎是以前几个问题的重复,但到目前为止这些都没有帮助我: - /
我编写了一个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
Apache conf:
<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并且app在调试器中本地运行良好
edit2:好的,解决方案是在sys.path中 - 我已经安装了最新的pandas RC,它位于非标准路径上,这就是为什么当我只添加std site-packages时它不起作用的原因单独的道路:
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')
...工作 - 感谢所有人!
答案 0 :(得分:-1)
我的猜测将是apache正在运行与您用于测试应用程序的Python不同的Python。