【问题标题】:Python 3.1 - Error while adding a library in BlenderPython 3.1 - 在 Blender 中添加库时出错
【发布时间】:2011-05-05 08:04:35
【问题描述】:

对于这个问题 (stackoverflow.com/questions/4086435/),我尝试制作 Python 3 版本的库 python-websocket (github.com/mtah/python-websocket/),这是我的代码:@ 987654321@.

Blender 带有他自己的 Python 3.1 包,所以我将我的文件直接添加到它的 «site-packages» 文件夹中。我现在收到此错误:

回溯(最近一次通话最后): 文件“websocket.py”,第 6 行,在 AttributeError:“模块”对象没有属性“WebSocket”

在 Blender 中运行此代码时:


import sys, os, asyncore, websocket

def msg_handler(msg): print(msg)

socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler) socket.onopen = lambda: socket.send('Hello world!')

try: asyncore.loop() except KeyboardInterrupt: socket.close()

我发现需要__init__.py,所以我添加了,但它没有帮助...... 我在这里做错了什么?感谢您的帮助。

【问题讨论】:

    标签: python websocket blender


    【解决方案1】:

    看起来您将脚本称为websocket.py,因此websocket 的导入会找到脚本本身,而不是使用该名称安装的模块。将脚本重命名为其他名称(如果它创建了 websocket.pyc 文件,请将其删除。)

    【讨论】:

    • 感谢您的回复,我重命名了脚本 python-websocket.py 但我有同样的错误。没有 websocket.pyc。
    • 好吧,对不起……它有效,我误解了你所说的。再次感谢!
    猜你喜欢
    • 2020-07-16
    • 1970-01-01
    • 2011-06-24
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    相关资源
    最近更新 更多