ubuntu中pip安裝redis-py及pip的使用


安裝redis-py的前提是已經將redis成功安裝,redis安裝過程請看博文

  ubuntu14安裝redis

1.安裝pip

sudo apt-get install python-pip

 

2.使用pip安裝redis-py

sudo pip install redis

 

3.此時便可以在python中使用redis了

 1 pc@pc-virtual-machine:~/Desktop$ python
 2 Python 2.7.6 (default, Jun 22 2015, 18:00:18) 
 3 [GCC 4.8.2] on linux2
 4 Type "help", "copyright", "credits" or "license" for more information.
 5 >>> import redis
 6 >>> r = redis.Redis(host = "localhost")
 7 >>> r.set("name","good night");
 8 True
 9 >>> r.get("name")
10 'good night'
11 >>> 

 

4.pip的使用詳解

4.1pip安裝包

  pip install SomePackage

      [...]
  Successfully installed SomePackage
 
4.2 pip檢查哪些包需要升級
  pip list --outdate
 
4.3 pip升級包
  pip install --upgrade SomePackage
 
4.4 pip卸載包
  pip uninstall SomePackage
  Uninstalling SomePackage:
    /my/env/lib/pythonx.x/site-packages/somepackage
  Proceed (y/n)? y
  Successfully uninstalled SomePackage
 
4.5 pip幫助
  

pip --help

Usage:
pip <command> [options]

Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
help Show help for commands.

 

 

 4.6 ubuntu下會經常使用pip安裝一些包,默認使用國外的鏡像源,下載比較慢。可以將鏡像源設置成國內的。國內有清華、阿里、中科大。

臨時使用:
可以在使用pip的時候加參數-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,這樣就會從清華這邊的鏡像去安裝pyspider庫。
 
長久使用,修改配置文件
Linux下,修改 ~/.pip/pip.conf (沒有就創建一個文件夾及文件。文件夾要加“.”,表示是隱藏文件夾)
內容如下:
[global]  
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

清華大學的pip源,它是官網pypi的鏡像,每隔5分鍾同步一次

 

 


免責聲明!

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



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