Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

redis

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

like image 518
cz75robert Avatar asked Mar 26 '13 23:03

cz75robert


1 Answers

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.

like image 73
kindall Avatar answered Oct 06 '22 21:10

kindall