简体   繁体   中英

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

I installed redis-py on CentOS and Ubuntu. 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:

>>> 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. Any idea what I'm doing wrong, and how to fix it. Probably a newbie Python thing...

You're naming a module you're working on redis.py and Python is importing that instead of the real redis module. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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