Python 3.1 - 在 Blender 中添加库时出错

标签 python websocket blender

对于这个问题(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/

相关文章:

python - Panda3d Blender 创建的房间无法正确显示

animation - OpenGL中眼睛模型瞳孔收缩/扩张的基本方法

python - matplotlib:仅将标记应用于起点或终点?

python - 将多个目标文档与多个源文档进行比较

python - Azure 认知服务 - 使用 python 和 websockets 自定义语音

c - IRC 程序不打印最后一条消息

three.js - SceneImporter 未加载 r68 中的 MeshFaceMaterial 纹理

python - 如何在本例中激活 ValidationError

Python错误: can't install scipy.优化.brentq

php - exec php 需要很长时间