For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.
开发者_如何转开发Blender comes with his own Python 3.1 package, so I added my file directly in its «site-packages» folder. I get this error now:
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
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()
I found that a __init__.py
is needed so I added but it didn't help…
What I am doing wrong here ? Thanks for your help.
It looks like you called your script websocket.py
, so the import of websocket
finds the script itself, instead of the installed module by that name. Rename the script to something else (and if it created a websocket.pyc
file, delete that.)
精彩评论