Python redis py AttributeError:&x27;模块';对象没有属性
我在CentOS和Ubuntu上安装了redis py。在这两种情况下,我在尝试访问时都会遇到相同的错误Python redis py AttributeError:&x27;模块';对象没有属性,python,redis,Python,Redis,我在CentOS和Ubuntu上安装了redis py。在这两种情况下,我在尝试访问时都会遇到相同的错误 redis-py AttributeError: 'module' object has no attribute 如果我在与源代码相同的目录中使用python提示符,这将起作用: >>> import redis >>> r = redis.Redis(host='localhost', port=6379, db=0) 但如果我更改目录,它将给出错
redis-py AttributeError: 'module' object has no attribute
如果我在与源代码相同的目录中使用python提示符,这将起作用:
>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
但如果我更改目录,它将给出错误
>>> import redis
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "redis.py", line 4, in <module>
print redis.__version__
AttributeError: 'module' object has no attribute '__version__'
导入redis
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“redis.py”,第4行,在
打印redis.\u版本__
AttributeError:“模块”对象没有属性“\uu版本”
尝试使用
.py
脚本总是会出现错误。知道我做错了什么,以及如何修复吗。可能是一个新手Python的东西 您正在命名正在处理的模块redis.py
,Python正在导入该模块,而不是真正的redis
模块。不要这样做,或者更改sys.path以确保当前工作目录是要搜索的目录列表中的最后一个,而不是第一个。我在tornado中遇到了这个错误,这是因为我在python 2.7上安装了redis,在python3中也安装了redis,我从python2.7中卸载redis,然后在python3中重新安装并解决了这个问题 您能给我们更多关于如何安装redis py的信息吗