Я проверяю использование Redis Queue в виртуальной среде.Структура каталогов следующая:
Scripts-V3 (Virtualenv is at this level)
├── RQ
│ ├── countwords.py
│ └── queue.py
Это тот же пример, что приведен в документации .
queue.py is:
from redis import Redis
from rq import Queue
from countwords import count_words_at_url
import time
# Tell RQ what Redis connection to use
redis_conn = Redis()
q = Queue(connection=redis_conn) # no args implies the default queue
# Delay execution of count_words_at_url('http://nvie.com')
job = q.enqueue(count_words_at_url, 'http://nvie.com')
print(job.result) # => None
# Now, wait a while, until the worker is finished
time.sleep(2)
print(job.result)
Я проверил, что установлены необходимые пакеты (redis, rq):
> pip3 install rq
Requirement already satisfied: rq in /Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages (1.0)
Requirement already satisfied: redis>=3.0.0 in /Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages (from rq) (3.2.1)
Requirement already satisfied: click>=5.0 in /Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages (from rq) (7.0)
Тем не менее, когда я запускаю python3 queue.py
, происходит сбой:
Traceback (most recent call last):
File "queue.py", line 1, in <module>
from rq import Queue
File "/Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages/rq/__init__.py", line 6, in <module>
from .connections import (Connection, get_current_connection, pop_connection,
File "/Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages/rq/connections.py", line 7, in <module>
from redis import Redis
File "/Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages/redis/__init__.py", line 1, in <module>
from redis.client import Redis, StrictRedis
File "/Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages/redis/client.py", line 10, in <module>
from redis._compat import (basestring, imap, iteritems, iterkeys,
File "/Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages/redis/_compat.py", line 106, in <module>
from queue import Queue
File "/Users/abc/Work/driver-pic-orient/Scripts-V3/RQ/queue.py", line 1, in <module>
from rq import Queue
ImportError: cannot import name 'Redis' from 'redis' (/Users/abc/Work/driver-pic-orient/venv/lib/python3.7/site-packages/rq/__init__.py)
Я не могу понять почему.Что происходит?