初次使用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,
嘗試無果,
嘗試性解決方法四:
新手常犯錯誤,
檢查運行檔案名稱與模塊名稱是否重復,如果重復,需要將檔案名稱重新命名,

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/233028.html
標籤:其他
上一篇:mysql 實作全連接
