错误" ImportError:没有名为request"的模块在Bluemix中启动Python 3应用程序

时间:2015-04-17 12:40:09

标签: python python-3.x python-3.4 ibm-cloud

我正在尝试在Bluemix中启动我的Python 3应用程序,它一直在说它试图启动。

-----> Uploading droplet (32M)

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 starting

我也在日志中收到关于无法找到请求的错误。我有什么想法吗?

2015-04-17T08:35:50.88-0400 [App/0]   ERR Traceback (most recent call last):
2015-04-17T08:35:50.88-0400 [App/0]   ERR   File "server.py", line 7, in <module>
2015-04-17T08:35:50.88-0400 [App/0]   ERR     from wordnik import *
2015-04-17T08:35:50.88-0400 [App/0]   ERR   File "/app/.heroku/python/lib/python2.7/site-packages/wordnik/swagger.py", line 10, in <module>
2015-04-17T08:35:50.88-0400 [App/0]   ERR     import urllib.request, urllib.error, urllib.parse
2015-04-17T08:35:50.88-0400 [App/0]   ERR ImportError: No module named request
2015-04-17T08:35:50.96-0400 [DEA]     ERR Instance (index 0) failed to start accepting connections

2 个答案:

答案 0 :(得分:1)

我能够通过显式调用我需要的Python版本来解决这个问题。在当前的buildpack中,Bluemix使用Python 2.7.9。

要调出要使用的Python版本,我在应用的根目录中创建了一个名为runtime.txt的文件。 runtime.txt的内容如下:

python-3.4.1

答案 1 :(得分:-1)

Bluemix上Python类似启动错误的另一个可能原因是缺少requirements.txt中的依赖项。 Ryan Baxter在他的博文Deploying A Python App To BlueMix中阐述了这一点。

为了完整起见,他继续指出导致难以理解的错误的其他问题,例如:(1)Python buildpack级别与Bluemix / Cloud Foundry不兼容;(2)应用程序无法从中检索端口用于启动HTTP服务器的环境变量VCAP_APP_PORT。后者的症状是一个在本地工作得很好的应用程序,但一旦部署就崩溃并出现错误"failed to start accepting connections"。如果你看到这个错误并且刮了一会儿,不要心疼;这是每个人在第一次部署时所犯的错误。