ImportError: No module named queue - Flask app on Cloud Foundry

折月煮酒 提交于 2019-12-11 15:24:50

问题


I am trying to push a flask app (Python 3.5) to Cloud Foundry (CF). The application takes a POST request (text file) and returns a message. It works locally (tested via Postman). However, when attempting to push it to CF, it gives the error -

ImportError: No module named queue

Here is my code which contains queue.

import queue as Queue
self._batch_queue = Queue.Queue(self.BATCH_QUEUE_MAX)
self._example_queue = Queue.Queue(self.BATCH_QUEUE_MAX * self._hps.batch_size)

I've tried the solutions suggested here, but neither of these solve my problem. I think the issue is with the Python in CF not having queue package. (I could be wrong).

Anyone ideas on how to go about solving this will be very appreciated. Thanks in advance!


回答1:


As mentioned in the comments by @KlausD, it seems like you have the wrong version of Python installed. On Cloud Foundry, you would set the version by including a file called runtime.txt in the root of your project (i.e. the directory from which you're running cf push).

https://docs.cloudfoundry.org/buildpacks/python/index.html#runtime

That file is used to tell the Python buildpack which version of Python to install for you. Suggestions would be python-3.5.x or python-3.6.x which would install the latest 3.5 or 3.6 release. You can specify an exact version like python-3.5.5 but it's not recommended as it's easy to forget to update that file when new versions of Python come out.

You can see which versions of Python are supported by the buildpack here.

https://buildpacks.cloudfoundry.org/#/buildpacks/python/v1.6.17

(Note that link goes to the latest version of the buildpack at the time I wrote this, it will get out of date. In the future, just click the most recent version of the buildpack to see what ships with it).



来源:https://stackoverflow.com/questions/50812817/importerror-no-module-named-queue-flask-app-on-cloud-foundry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!