Python踩坑系列之使用redis報錯:module 'redis' has no attribute 'Redis'問題

初次使用redis時,在連接Redis後,運行報錯「module 'redis' has no attribute '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

嘗試無果。code

 

 嘗試性解決方法二:blog

在pycharm中file --> setting --> Project Interpreter 下選擇redis進行導入,完成後,從新運行。ip

嘗試無果。get

 

 嘗試性解決方法三:pycharm

(1)手動下載redis模塊,地址爲:https://github.com/andymccurdy/redis-py,

(2)而後進行解壓:redis-py-master.zip,

(3) cd redis-py-master  進入到該路徑下,

(4)執行 python setup.py install 命令安裝redis。

嘗試無果。

 

嘗試性解決方法四:

新手常犯錯誤。

檢查運行文件名稱與模塊名稱是否重複。若是重複,須要將文件名稱從新命名。

相關文章
相關標籤/搜索