这可能是一个重复的问题,但我仍无法解决目前的情况。我试图在localhost端口8080上部署一个烧瓶应用程序,但我正在运行导入错误。这是详细信息:
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] mod_wsgi (pid=5400): Target WSGI script '/home/btruhand/public_html/wsgi/TwitterIntersection.wsgi' cannot be loaded as Python module. [Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] mod_wsgi (pid=5400): Exception occurred processing WSGI script '/home/btruhand/public_html/wsgi/TwitterIntersection.wsgi'.
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] File "/home/btruhand/public_html/wsgi/TwitterIntersection.wsgi", line 5, in <module>
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] from twitterintersect import app as application [Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] File "/home/btruhand/public_html/apps/TwitterIntersection/twitterintersect/__init__.py", line 8, in <module>
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] from twitterintersect import views
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] File "/home/btruhand/public_html/apps/TwitterIntersection/twitterintersect/views.py", line 1, in <module>
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] from twitterintersect import app, db, hackedtwitter, tasks [Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] File "/home/btruhand/public_html/apps/TwitterIntersection/twitterintersect/tasks.py", line 1, in <module>
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] from twitterintersect import app, db_models, hackedtwitter, appInfo
[Sun Feb 09 14:32:29 2014] [error] [client 127.0.0.1] ImportError: cannot import name hackedtwitter
twitterintersect是一个包,它的布局如下:
TwitterIntersection/
---twitterintersect/
-----__init__.py
-----views.py
-----tasks.py
-----hackedtwitter.py
-----some other files
TwitterIntersection在〜/ public_html / apps /
中在这里提供更多信息是〜/ public_html / wsgi中的TwitterIntersection.wsgi文件:
activate_this='/home/btruhand/public_html/apps/TwitterIntersection/bin/activate_this.py'
execfile(activate_this,dict(__file__=activate_this))
import sys
sys.path.append('/home/btruhand/public_html/apps/TwitterIntersection/')
from twitterintersect import app as application
这是我的站点配置文件,它已激活并位于/ etc / apache2 / sites-available:
<VirtualHost *:8080>
# ---- Configure VirtualHost Defaults ----
ServerAdmin root@localhost
DocumentRoot /home/btruhand/public_html/http
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/btruhand/public_html/http/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
# ---- Configure WSGI Listener(s) ----
WSGIDaemonProcess TwitterIntersection user=www-data group=www-data threads=5
WSGIScriptAlias /twitterintersection /home/btruhand/public_html/wsgi/TwitterIntersection.wsgi
<Directory /home/btruhand/public_html/http/twitterintersection>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# ---- Configure Logging ----
ErrorLog /home/btruhand/public_html/logs/error_twitter_intersection.log
LogLevel warn
CustomLog /home/btruhand/public_html/logs/access_twitter_intersection.log combined
</VirtualHost>
对于发生的事情感到非常困惑。手动使用python命令执行TwitterIntersection.wsgi不会造成问题。
编辑: 哦,我忘了提到app和db都是在__init__.py中定义的。把它拿出去以防万一
EDIT2: 好吧,我设法让事情顺利进行。正如Graham Dumpleton所指出的那样,对于遇到与我相同问题的任何人,请确保用户可以在配置文件中的WSGIDaemonProcess配置下访问包中的文件。