我有一个非常简单的BottlePy应用程序,它有一个使用subprocess.Popen启动新进程的路由。使用命令一切都很好:
mod_wsgi-express start-server app.wsgi
首先,在尝试apache配置时,我遇到了一个奇怪的异常,可能与pyMongo有关。
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/__init__.py", line 3, in <module>
import fields
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/fields.py", line 6, in <module>
import urllib2
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in <module>
import mimetools
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
我的配置是:
的httpd.conf:
WSGIPythonPath "/usr/local/lib/python2.7/site-packages"
httpd.vhosts.conf:
<VirtualHost *:80>
ServerName relferreira.com
WSGIDaemonProcess relferreira user=relferreira group=staff processes=1 threads=5
WSGIScriptAlias "/" "/Users/relferreira/Documents/app.wsgi"
WSGIProcessGroup relferreira
<Directory "/Users/relferreira/Documents/">
WSGIProcessGroup relferreira
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
ErrorLog /Users/relferreira/Documents/api/error-bottle.log
CustomLog /Users/relferreira/Documents/api/access-bottle.log combined
</VirtualHost>
路线(简化): 如您所见,我需要将路径传递给子流程,以便能够加载模块
@route('/extract')
def extract():
try:
script_path = .....
command = .....
env = os.environ.copy()
env['PYTHONPATH'] = ":".join(sys.path)
proc = subprocess.Popen(['python', script_path] + command, env=env)
except SystemExit as e:
abort(400, 'Wrong parameters')
return 'success'
otool -L:
command: otool -L /usr/local/lib/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
返回:
/usr/local/lib/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so:
/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
我使用Homebrew
安装了Python。我知道我应该使用virtualenv,put是一个遗留项目所以,我试图让它在没有它的情况下工作。