문제

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.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top