ImportError:没有名为队列的模块-Cloud Foundry上的Flask应用

ImportError:没有名为队列的模块-Cloud Foundry上的Flask应用

问题描述:

我正在尝试将Flask应用程序(Python 3.5)推送到Cloud Foundry(CF).该应用程序接收POST请求(文本文件)并返回一条消息.它在本地工作(通过Postman测试).但是,当尝试将其推送到CF时,会出现错误-

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:没有名为队列的模块

ImportError: No module named queue

这是我的代码,其中包含 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)

我已经尝试了建议的解决方案在这里,但是这些都不能解决我的问题.我认为问题出在CF中的Python没有队列包. (我可能是错的).

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!

如@KlausD的注释中所述,似乎您安装了错误的Python版本.在Cloud Foundry上,您可以通过在项目的根目录(即运行cf push的目录)中包含一个名为runtime.txt的文件来设置版本.

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

该文件用于告诉Python buildpack为您安装哪个版本的Python.建议使用python-3.5.xpython-3.6.x,它们将安装最新的3.5或3.6版本.您可以指定一个精确的版本,例如python-3.5.5,但不建议这样做,因为当新的Python版本问世时,很容易忘记更新该文件.

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.

您可以在此处查看buildpack支持哪些Python版本.

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

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

(请注意,在我撰写本文时,该链接指向该buildpack的最新版本,它将过时.将来,只需单击该buildpack的最新版本即可查看随附的版本).

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