【问题标题】:Python27 qpid: ImportError: No module named _cprotonPython27 qpid:ImportError:没有名为 _cproton 的模块
【发布时间】:2014-08-12 19:45:12
【问题描述】:

我尝试执行以下代码,但不幸的是我收到以下错误。任何建议都非常感谢。 我在 c:\Python27\Lib\site-packages
中有以下文件 1) cproton.py
2) 质子.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

【问题讨论】:

    标签: python amqp qpid


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,我会调查的。
    【解决方案2】:

    嘿,你使用我的代码很棒:)。 尝试调试有什么问题。 你能在 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 在错误的目录中搜索。 这只是一个猜测。 让我知道输出。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 2017-12-30
    • 2018-01-06
    • 2018-11-11
    • 2015-04-10
    • 2013-11-27
    相关资源
    最近更新 更多