简体   繁体   English

redis-py AttributeError:'module'对象没有属性

[英]redis-py AttributeError: 'module' object has no attribute

I installed redis-py on CentOS and Ubuntu. 我在CentOS和Ubuntu上安装了redis-py。 On both I get the same error when trying to access it. 在我尝试访问它时,我得到相同的错误。

redis-py AttributeError: 'module' object has no attribute

If I use the python prompt in the same directory as the source this will work: 如果我在与源相同的目录中使用python提示符,这将起作用:

>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)

but if I change directories it will give the error. 但如果我更改目录,它将给出错误。

>>> 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__'

Trying with a .py script always gives the error. 尝试使用.py脚本始终会出错。 Any idea what I'm doing wrong, and how to fix it. 知道我做错了什么,以及如何解决它。 Probably a newbie Python thing... 可能是一个新手Python的东西......

You're naming a module you're working on redis.py and Python is importing that instead of the real redis module. 您正在命名一个正在处理redis.py的模块,Python正在导入而不是真正的redis模块。 Don't do that, or change sys.path to make sure the current working directory is last rather than first in the lists of directories to search. 不要这样做,或者更改sys.path以确保当前工作目录在搜索目录列表中是最后一个而不是第一个。

我在龙卷风中有这个错误,这是因为我在python 2.7上安装redis并安装在python3中,我从python2.7卸载redis并在python3中重新安装并解决问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM