有两个实例运行 uwgsi 和 nginx 服务器。每个托管一个 Flask 应用程序。两者都在 Python 2.7.3 路径上运行。其中一台服务器为“import simplejson”语句引发 ImportError。两台服务器上的解释器都会毫无怨言地接受这个导入语句。
这是应用程序A的来源:
1 from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash, views
2 import sys
3 print sys.version
4 print sys.path
5
6 import os
7 import functools
8 import urllib,urllib2
9 import simplejson
10 from datetime import datetime, timedelta
以及应用B的来源:
1 from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash, views
2
3 import sys
4 print sys.version
5 print sys.path
6
7 import simplejson
8
9 import functools
这是服务器 A 的 sys.version 和 sys.path 日志输出:
2.7.3 (default, Aug 1 2012, 05:25:23)
[GCC 4.6.3]
['/srv/www/A/env/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/srv/www/A/env/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
'/srv/www/A/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/srv/www/A/env/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
'/srv/www/A/env/lib/python2.7',
'/srv/www/A/20120910/src',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/srv/www/A/env/local/lib/python2.7/site-packages',
'/srv/www/A/env/lib/python2.7/site-packages']
WSGI app 0 (mountpoint='notimportant.com|') ready in 1 seconds on interpreter 0x1b20420 pid: 11069
这是服务器 B 的 sys.version 和 sys.path 日志输出:
2.7.3 (default, Aug 1 2012, 05:25:23)
[GCC 4.6.3]
['/srv/www/B/env/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/srv/www/B/env/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
'/srv/www/B/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/srv/www/B/env/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
'/srv/www/B/env/lib/python2.7',
'/srv/www/B/20130105/src',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/srv/www/B/env/local/lib/python2.7/site-packages',
'/srv/www/B/env/lib/python2.7/site-packages']
Traceback (most recent call last):
File "/srv/www/B/20130105/src/B.py", line 7, in <module>
import simplejson
ImportError: No module named simplejson
unable to load app 0 (mountpoint='notimportant.com|') (callable not found or import error)
任何建设性的想法将不胜感激。