Python踩坑系列之使用redis報錯:module 'redis' has no attribute 'Redis'問題
阿新 • • 發佈:2020-12-11
初次使用redis時,在連結Redis後,執行報錯“module 'redis' has no attribute 'Redis' ”。
具體程式碼如下:
import redis r = redis.Redis(host='192.168.2.22',port=6379,db=2) r.set('name','Delia') print(r.get('name'))
報錯如下:
嘗試性解決方法一:
在Python安裝路徑下使用pip安裝redis,重新執行程式;
pip install redis
嘗試無果。
嘗試性解決方法二:
在pycharm中file --> setting --> Project Interpreter 下選擇redis進行匯入,完成後,重新執行。
嘗試無果。
嘗試性解決方法三:
(1)手動下載redis模組,地址為:https://github.com/andymccurdy/redis-py,
(2)然後進行解壓:redis-py-master.zip,
(3) cd redis-py-master 進入到該路徑下,
(4)執行 python setup.py install 命令安裝redis。
嘗試無果。
嘗試性解決方法四:
新手常犯錯誤。
檢查執行檔名稱與模組名稱是否重複。如果重複,需要將檔名稱重新命名。