ModuleNotFoundError: No module named 'redis'
Closed this issue · 5 comments
firmianay commented
I use pip to install pyrate-limiter.
from pyrate_limiter import Duration, Limiter, RequestRate
File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/pyrate_limiter/__init__.py", line 3, in <module>
from .buckets import *
File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/pyrate_limiter/buckets/__init__.py", line 5, in <module>
from .redis_bucket import RedisBucket
File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/pyrate_limiter/buckets/redis_bucket.py", line 10, in <module>
from redis import Redis
ModuleNotFoundError: No module named 'redis'
➜ ~ python3 -m venv ~/.virtualenvs/test
➜ ~ source ~/.virtualenvs/test/bin/activate
(test) ➜ ~ pip install pyrate-limiter
Collecting pyrate-limiter
Obtaining dependency information for pyrate-limiter from https://files.pythonhosted.org/packages/7a/c8/1f5bf1c38ac89e3140754caac84bc09feeca92881680bc2a097d7cdc567b/pyrate_limiter-3.0.1-py3-none-any.whl.metadata
Downloading pyrate_limiter-3.0.1-py3-none-any.whl.metadata (21 kB)
Downloading pyrate_limiter-3.0.1-py3-none-any.whl (22 kB)
Installing collected packages: pyrate-limiter
Successfully installed pyrate-limiter-3.0.1
(test) ➜ ~ pip list
Package Version
-------------- -------
pip 23.2.1
pyrate-limiter 3.0.1
setuptools 68.1.2
vutran1710 commented
Oops, my bad. Fixing now
vutran1710 commented
fixed in 3.0.2
firmianay commented
Thanks! I found that this version has changed a lot. My previous code looks like this. How can I modify it?
def send(self, text_list: list):
limiter = Limiter(RequestRate(20, Duration.MINUTE))
for text in text_list:
with limiter.ratelimit('identity', delay=True):
...
r = requests.post(url=url, headers=headers, data=json.dumps(data))
vutran1710 commented
Oh you can change it into something like this
from pyrate_limiter import Duration, Rate, InMemoryBucket, Limiter
rates = [Rate(20, Duration.MINUTE)]
bucket = InMemoryBucket(rates)
# lets say you want to delay until it can consume, the max-delay can be set to equal the rate's interval
limiter = Limiter(bucket, max_delay=Duration.MINUTE.value)
for text in text_lists:
limiter.try_acquire('identity')
r = requests.post(...)
firmianay commented
It worked, thanks