ImportError: No module named queue - Flask app on

2019-08-20 07:43发布

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条回答
贼婆χ
2楼-- · 2019-08-20 08:04

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).

查看更多
登录 后发表回答