Running python IBM Cloud Apps Cloud Foundry with error in ModuleNotFoundError: No module named 'matplotlib'

Running python IBM Cloud Apps Cloud Foundry with error in ModuleNotFoundError: No module named 'matplotlib'

部署到 IBM Cloud - App Cloud Foundry 使用 Python - Django 后,我发现以下错误 运行 连接容器:

APP/PROC/WEB    0   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed    
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "<frozen importlib._bootstrap_external>", line 678, in exec_module 
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked   
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   callback, param_dict = resolver.resolve_error_handler(500)  
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "/home/vcap/deps/0/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 141, in handle_uncaught_exception   
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())  
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "/home/vcap/deps/0/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 103, in response_for_exception  
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   response = response_for_exception(request, exc) 
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "/home/vcap/deps/0/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 49, in inner    
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   response = self._middleware_chain(request)  
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "/home/vcap/deps/0/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in get_response 
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   response = self.get_response(request)   
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "/home/vcap/deps/0/python/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 133, in __call__ 
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   respiter = self.wsgi(environ, resp.start_response)  
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "/home/vcap/deps/0/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 176, in handle_request   
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   self.handle_request(listener, req, client, addr)    
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   File "/home/vcap/deps/0/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle   
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   Traceback (most recent call last):  
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   During handling of the above exception, another exception occurred: 
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   **ModuleNotFoundError: No module named 'matplotlib'**   
13 de mar. de 2021 10:43:24
APP/PROC/WEB    0   import matplotlib.pyplot as plt

在我的本地环境中 运行ning ibmcloud dev buildibmcloud dev 运行 工作正常,但是在 IBM Cloud 中部署后,日志中出现错误。

这是我的 Dockerfile:

FROM registry.access.redhat.com/ubi8:8.3

WORKDIR /app

COPY Pipfile* /app/

## NOTE - rhel enforces user container permissions stronger ##
USER root
RUN yum -y install python3
RUN yum -y install python3-pip wget

RUN pip3 install --upgrade pip==21.0.1 \
  && pip3 install --upgrade pipenv==2020.11.15 \
  && pipenv install --system --deploy

RUN pip3 install numpy
RUN pip3 install wordcloud
RUN pip3 install requests
RUN pip3 install urllib3
RUN pip3 install matplotlib --force
RUN pip3 install six wikipedia-API --force


USER 1001

COPY . /app

ENV PORT 3000

EXPOSE 3000

CMD ["python3", "manage.py", "start"]

这是我的 manifest.yml

---
applications:
- instances: 1
  timeout: 180
  name: biblestatistic
  buildpack: python_buildpack
  command: gunicorn --env DJANGO_SETTINGS_MODULE=pythondjangoapp.settings.production pythondjangoapp.wsgi -b 0.0.0.0:$PORT
  memory: 1024MB
  domain: us-south.cf.appdomain.cloud
  host: <my_host>

您的 Dockerfile 用于 运行 作为容器的应用程序。使用 Cloud Foundry,您确实需要一个 requirements.txt,其中包含您的应用所依赖的所有模块。您还需要 runtime.txt 来指定 Python 版本。看看这个 Cloud Foundry documentation on the Python buildpack and the required configuration files.