对于这个问题(stackoverflow.com/questions/4086435/),我尝试制作Python 3版本的库python-websocket(github.com/mtah/python-websocket/),这是我的代码:https://gist.github.com/663175 .
Blender 附带了自己的 Python 3.1 包,因此我将文件直接添加到其“site-packages”文件夹中。我现在收到此错误:
Traceback (most recent call last): File "websocket.py", line 6, in AttributeError: 'module' object has no attribute 'WebSocket'
when running this code in Blender:
import sys, os, asyncore, websocket<p></p>
<p>def msg_handler(msg):
print(msg)</p>
<p>socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler)
socket.onopen = lambda: socket.send('Hello world!')</p>
<p>try:
asyncore.loop()
except KeyboardInterrupt:
socket.close()
</p>
我发现需要一个__init__.py
,所以我添加了,但没有帮助......
我在这里做错了什么?感谢您的帮助。
最佳答案
看起来您调用了脚本 websocket.py
,因此 websocket
的导入会找到脚本本身,而不是使用该名称安装的模块。将脚本重命名为其他名称(如果它创建了 websocket.pyc
文件,请将其删除。)
关于Python 3.1 - 在 Blender 中添加库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4101621/