gpt4 book ai didi

python - (Another) ImportError with Flask under mod_wsgi

转载 作者:太空宇宙 更新时间:2023-11-04 06:43:06 26 4
gpt4 key购买 nike

很抱歉,如果这看起来像是重复了之前的几个问题,但到目前为止,这些问题都没有帮助我:-/

我已经编写了一个 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 配置文件:

<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,它位于非标准路径上,这就是为什么当我简单地添加标准站点包时它不起作用的原因单独路径:

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')

...工作 - 感谢所有人!

最佳答案

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

关于python - (Another) ImportError with Flask under mod_wsgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16179967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com