【问题标题】:import create_connection fails in python 2.7在 python 2.7 中导入 create_connection 失败
【发布时间】:2016-05-17 03:43:52
【问题描述】:

我正在 bluemix 上编写一个 websocket 程序,并遇到了 import create_connection 的一些问题: 从 websocket 导入 create_connection ImportError: 无法导入名称 create_connection

我可以知道解决方法是什么。我正在使用 python 2.7 在 IBM Bluemix 上运行

添加细节: 我已经在 Python notebook 中安装了 websocket 包,然后运行了这段代码:

      6 import websocket
      7 print 'before connection'
----> 8 ws = websocket.create_connection("ws://tryandbuyoncloud.stage1.mybluemix.net/ws/Test")

     10 print "Sending 'Hello, World'..."

AttributeError: 'module' object has no attribute 'create_connection'

-达塔

【问题讨论】:

  • Heu Datta,你能提供完整的日志输出和你的代码吗?
  • 您有列出正确依赖项的 requirements.txt 文件吗?
  • 嗨,我没有 requirements.txt,因为我使用的是 python 笔记本,而不是在 bluemix 上部署应用程序。
  • 嗨霍伯特,我已经添加了程序和错误详细信息。

标签: python-2.7 websocket ibm-cloud


【解决方案1】:

今天发生在我身上。好像您使用的包是websocket 而不是websocket-client。卸载websocket 和websocket-client(如果有的话),然后只安装websocket-client:

pip uninstall websocket
pip uninstall websocket-client
pip install websocket-client

卸载websocket-client然后重新安装它可能看起来多余,但对我来说这是必要的(卸载websocket后无法运行import websocket,即使安装了websocket-client。

【讨论】:

    【解决方案2】:

    我被这个错误困住了很长时间,即使在卸载 websocket 并安装 websocket-client 之后,它也无法正常工作。然后不知从何而来,卸载并重新安装 websocket-client 解决了错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-29
      • 2014-08-10
      • 1970-01-01
      • 2015-04-01
      • 2013-07-15
      • 2020-11-02
      • 1970-01-01
      • 2013-07-04
      相关资源
      最近更新 更多