0

I have checked

redis-server --version
Redis server v=4.0.8 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=4d30adc486b198e5

If I try to run my code

  File "app.py", line 5, in <module>
    import redis
ModuleNotFoundError: No module named 'redis'

Why?

6
  • 1
    You probably need pip install redis Commented Apr 3, 2018 at 20:17
  • Have you installed the redis python package? Commented Apr 3, 2018 at 20:18
  • @chrisz Yes,that's it,works fine. Commented Apr 3, 2018 at 20:22
  • 1
    @SuaMorales not necessarily. There is no reason to use sudo if you don't have to. In fact, I would say it's bad practice to default to using sudo to install python packages. Commented Apr 3, 2018 at 20:33
  • 1
    @chrisz recommended in the python docs: pypi.python.org/pypi/redis . Generally agree, tho Commented Apr 4, 2018 at 12:56

1 Answer 1

2

I was having the same problem running from inside a Jupyter Notebook. Very strange, if I used !pip freeze or !conda list it would throw the same error.

I eventually stumbled upon this post: https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/ And the code snippet that ultimately worked:

# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install redis
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.