Python 3.1 - Error while adding a library in Blender

 ̄綄美尐妖づ 提交于 2019-12-11 09:29:18

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/4101621/python-3-1-error-while-adding-a-library-in-blender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!