没有名为zmq的模块用于python代码

时间:2013-04-24 02:40:17

标签: python zeromq

当我尝试运行此脚本时

# -*- coding: utf-8 -*- 

#
#   Hello World client in Python
#   Connects REQ socket to tcp://localhost:5555
#   Sends "Hello" to server, expects "World" back
#


import zmq

context = zmq.Context()

#  Socket to talk to server
print "Connecting to hello world server…"
socket = context.socket(zmq.REQ)
socket.connect ("tcp://localhost:5555")

#  Do 10 requests, waiting each time for a response
for request in range (10):
    print "Sending request ", request,"…"
    socket.send ("Hello")

    #  Get the reply.
    message = socket.recv()
    print "Received reply ", request, "[", message, "]"

当我这样做时 - python peer.py

我得到ImportError: No module named zmq

但我已经使用 - easy_install pyzmq为zeromq安装了python绑定。 如何检查绑定是否安装不正确?

1 个答案:

答案 0 :(得分:1)

尝试“python -v peer.py” - 应显示正在搜索模块的路径。你可以在Linux上使用strace获得类似的结果,但在这种情况下python -v更有针对性。

还要考虑你的系统上有多个Python的可能性 - 如果你在Linux上使用bash,“type -all python”可能会提供信息。