初次使用redis時,在連接Redis後,運行報錯「No module named redis」。python
具體代碼以下:git
import redis r = redis.Redis(host='192.168.2.22',port=6379,db=2) r.set('name','Delia') print(r.get('name'))
報錯以下:github
嘗試性解決方法一:redis
在Python安裝路徑下使用pip安裝redis,從新運行程序;spa
pip install redis
嘗試無果。3d
嘗試性解決方法二:code
在pycharm中file --> setting --> Project Interpreter 下選擇redis進行導入,完成後,從新運行。blog
嘗試無果。ip
嘗試性解決方法三:get
(1)手動下載redis模塊,地址爲:https://github.com/andymccurdy/redis-py,
(2)而後進行解壓:redis-py-master.zip,
(3) cd redis-py-master 進入到該路徑下,
(4)執行 python setup.py install 命令安裝redis。
嘗試無果。
嘗試性解決方法四:
新手常犯錯誤。
檢查運行文件名稱與模塊名稱是否重複。若是重複,須要將文件名稱從新命名。