Python 3.1-在Blender中添加库时出错 [英] Python 3.1 - Error while adding a library in Blender

查看:178
本文介绍了Python 3.1-在Blender中添加库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个问题(stackoverflow.com/questions/4086435/),我试图制作Python 3版本的库python-websocket(github.com/mtah/python-websocket/),这是我的代码: https://gist.github.com/663175 .

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带有他自己的Python 3.1软件包,因此我将文件直接添加到其"site-packages"文件夹中.我现在收到此错误:

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'

在Blender中运行此代码时:

when running this code in Blender:


import sys, os, asyncore, websocket

def msg_handler(msg): print(msg)

def msg_handler(msg): print(msg)

socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler) socket.onopen = lambda: socket.send('Hello world!')

socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler) socket.onopen = lambda: socket.send('Hello world!')

try: asyncore.loop() except KeyboardInterrupt: socket.close()

try: asyncore.loop() except KeyboardInterrupt: socket.close()

我发现需要一个__init__.py,所以我添加了它,但没有帮助… 我在这里做错了什么?感谢您的帮助.

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.

推荐答案

您似乎将脚本称为websocket.py,因此,导入websocket会查找脚本本身,而不是该名称的已安装模块.将脚本重命名为其他名称(如果创建了websocket.pyc文件,则将其删除.)

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

这篇关于Python 3.1-在Blender中添加库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆