Python ImportError:在docker容器上使用mod_wsgi时,没有名为time的模块
我有一个flask应用程序,它通过apache/mod_wsgi提供服务,运行在AWS-EC2 Ubuntu 16.04服务器实例上的Docker容器上 我得到的错误是:Python ImportError:在docker容器上使用mod_wsgi时,没有名为time的模块,python,docker,flask,mod-wsgi,paraview,Python,Docker,Flask,Mod Wsgi,Paraview,我有一个flask应用程序,它通过apache/mod_wsgi提供服务,运行在AWS-EC2 Ubuntu 16.04服务器实例上的Docker容器上 我得到的错误是: [Wed Mar 27 10:08:55.430668 2019] [mpm_event:notice] [pid 6:tid 139857176496000] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.6.5 Python/2.7 configured -- resuming no
[Wed Mar 27 10:08:55.430668 2019] [mpm_event:notice] [pid 6:tid 139857176496000] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.6.5 Python/2.7 configured -- resuming normal operations
[Wed Mar 27 10:08:55.430783 2019] [core:notice] [pid 6:tid 139857176496000] AH00094: Command line: 'apache2 (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:9090:999/httpd.conf -D MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D FOREGROUND'
[Wed Mar 27 10:08:55.443834 2019] [wsgi:error] [pid 8:tid 139857176496000] mod_wsgi (pid=8): Failed to exec Python script file '/tmp/mod_wsgi-localhost:9090:999/handler.wsgi'.
[Wed Mar 27 10:08:55.443868 2019] [wsgi:error] [pid 8:tid 139857176496000] mod_wsgi (pid=8): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:9090:999/handler.wsgi'.
[Wed Mar 27 10:08:55.443886 2019] [wsgi:error] [pid 8:tid 139857176496000] Traceback (most recent call last):
[Wed Mar 27 10:08:55.443901 2019] [wsgi:error] [pid 8:tid 139857176496000] File "/tmp/mod_wsgi-localhost:9090:999/handler.wsgi", line 5, in <module>
[Wed Mar 27 10:08:55.443968 2019] [wsgi:error] [pid 8:tid 139857176496000] import time
[Wed Mar 27 10:08:55.443985 2019] [wsgi:error] [pid 8:tid 139857176496000] ImportError: No module named time
这是我的apache配置设置:
WSGIScriptAlias /postProcess /home/niramai/application/postProcessing_flask.wsgi
WSGIScriptReloading On
WSGIDaemonProcess website processes=2 threads=15 display-name=%{GROUP} python-path=/home/niramai/application/
<Directory /home/niramai/application>
Order allow,deny
Allow from all
</Directory>
我已经尝试将python路径添加到WSGIDaemonProcess,尝试添加sys.path以包含python库
尝试通过使用“chmod u+s postProcessing_flask.wsgi”设置组的setgid(小写“s”)来更改对文件夹的权限
尝试在mod_wsgi-express start server命令中附加LD_LIBRARY_路径并专门设置PYTHONPATH,但均无效
我是这个领域的新手,非常感谢您的帮助。第一步是尝试在Python之外重现同样的情况。你能在gunicorn下运行同样的脚本吗?它会产生同样的错误吗?(我觉得
sys.path
的显式设置不合适。)感谢您的评论,很抱歉回复太晚。多亏了Graham Dumpleton,我知道我丢失了一个包含时间模块的C扩展模块。我将Python2.7更新为Python3.6,解决了这个问题。你能在gunicorn下运行同样的脚本吗?它会产生同样的错误吗?(我觉得sys.path
的显式设置不合适。)感谢您的评论,很抱歉回复太晚。多亏了Graham Dumpleton,我知道我丢失了一个包含时间模块的C扩展模块。我将Python2.7更新为Python3.6,解决了这个问题。
WSGIScriptAlias /postProcess /home/niramai/application/postProcessing_flask.wsgi
WSGIScriptReloading On
WSGIDaemonProcess website processes=2 threads=15 display-name=%{GROUP} python-path=/home/niramai/application/
<Directory /home/niramai/application>
Order allow,deny
Allow from all
</Directory>
ARG BASE_IMAGE=kitware/paraviewweb:pv-osmesa-v5.6.0
FROM ${BASE_IMAGE}
ENV DEBIAN_FRONTEND=noninteractive
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/paraview/install/lib/:/usr/lib/python2.7
USER root
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y \
python2.7 \
python-pip \
python2.7-dev \
lsof \
apache2 \
apache2-dev \
vim \
libapache2-mod-wsgi
# pip install necesary python packages
RUN pip2 install \
Flask \
flask-restful \
boto3 \
requests \
mod_wsgi \
times
###################################################################################
# Start dumb_init as pid 1, to prevent any weird behaviour.
ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.1/dumb-init_1.1.1_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
# Default user is root, which could cause issues in case of a breakout.
RUN groupadd -r niramai && useradd -m -r -g niramai niramai
COPY paraview-wsgi.conf /etc/apache2/conf-enabled/
RUN service apache2 restart
RUN mkdir -p /home/niramai/application
WORKDIR /home/niramai/application
RUN ln -fs /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.py /usr/lib/python2.7/
USER niramai
COPY --chown=niramai:niramai . .
EXPOSE 9090
CMD ["dumb-init", "mod_wsgi-express", "start-server", "postProcessing_flask.wsgi", "--port", "9090", "--socket-timeout", "600" ]