Python27 qpid:ImportError:没有名为_cproton的模块

时间:2014-08-04 08:06:59

标签: python amqp qpid

我尝试执行以下代码但不幸的是我收到以下错误。任何建议都非常感谢。 我在c:\ Python27 \ Lib \ site-packages
中有以下文件 1)cproton.py
2)proton.py
3)_cproton.so

import sys
from cproton import *
from proton import *

#This code is for initiating the AMQP messenger
amqpmng = Messenger()
amqpmng._set_timeout(2000L) #Set timeout for sending and receiving at 2000 ms
address = "amqps://<<user>>:<<password>>@<<namespace>>.servicebus.windows.net/<<queue>>" 

#This code is for creating messages
msg = Message()
msg.subject = "This is a testmessage"
msg.body = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."

#This code is for sending messages
try:
    msg.address = address
    amqpmng.put(msg)
    amqpmng.send()
except:
    e = sys.exc_info()[0]
    print e, "Waited for 2s to send messages, nothing send, connection timed out"

amqpmng.stop();

#This code is for receiving messages
amqpmng.subscribe(address)
amqpmng.start()
try:
    amqpmng.recv(1) #receive exactly 1 message (you can enter any value)
    msg = Message()
    while amqpmng.incoming > 0:
        amqpmng.get(msg)
        print(msg.body)
except:
    e = sys.exc_info()[0]
    print e, "Waited for 2s to receive messages, nothing received, connection timed out"

amqpmng.stop()

错误:

    Traceback (most recent call last):

    File "receiv.py", line 2, in <module> from cproton import *

    File "C:\Python27\lib\site-packages\cproton.py", line 29, in <module>
           _cproton = swig_import_helper()

    File "C:\Python27\lib\site-packages\cproton.py", line 21, in swig_import_helpe
           r

    import _cproton

    ImportError: No module named _cproton

2 个答案:

答案 0 :(得分:2)

.so文件是用于UNIX系统的动态链接库。它不适用于Windows。

除非你能找到预先构建的Windows二进制文件,否则你将不得不自己编译它。您可以找到构建说明here

答案 1 :(得分:1)

嘿,你使用我的代码很棒:)。 尝试调试错误。 你能在cproton.py中更改这些行吗?

from sys import version_info
if version_info >= (2,6,0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module('_cproton', [dirname(__file__)])
            print fp #<-- manually added code
            print pathname #<-- manually added code
            print description #<-- manually added code
        except ImportError:
            import _cproton
            return _cproton
        if fp is not None:
            try:
                _mod = imp.load_module('_cproton', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _cproton = swig_import_helper()
    del swig_import_helper
else:
    import _cproton
del version_info

我认为python正在错误的目录中搜索。 这只是猜测。 让我知道输出。