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


初次使用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。

嘗試無果。

 

嘗試性解決方法四:

新手常犯錯誤。

檢查運行文件名稱與模塊名稱是否重復。如果重復,需要將文件名稱重新命名。

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM