【Python】設置pip源為國內源及簡單操作


一、pip國內源鏡像:

阿里雲:http://mirrors.aliyun.com/pypi/simple/
中國科技大學:https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban):http://pypi.douban.com/simple/
清華大學:https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學:http://pypi.mirrors.ustc.edu.cn/simple/

二、修改源方法:

1.臨時修改
可以在使用pip的時候在后面加上-index參數,指定pip源:

pip install --index https://pypi.tuna.tsinghua.edu.cn/simple requests

2.配置文件
Linux
①修改 ~/.pip/pip.conf (沒有就創建一個), 內容如下:

[root@localhost .pip]# cat ~/.pip/pip.conf 
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

②使用:

[root@localhost .pip]# pip install xlwt
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting xlwt
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/44/48/def306413b25c3d01753603b1a222a011b8621aed27cd7f89cbc27e6b0f4/xlwt-1.3.0-py2.py3-none-any.whl (99 kB)
     |████████████████████████████████| 99 kB 735 kB/s 
Installing collected packages: xlwt
Successfully installed xlwt-1.3.0

Windows:
①在我的電腦上的地址欄輸入:%appdata% ,然后回車;
②在里面新建一個名為 pip 的文件夾;
③在 pip 文件夾里面新建一個文件叫做 pip.ini ,內容寫如下即可。實際就是這么一個文件 : %appdata%\pip\pip.ini。
文件內容如下:

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

④使用pyreadline庫,可實現Windows中python的tab鍵補全,安裝如下:

C:\Users\annie.wu>pip install pyreadline
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pyreadline
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/7c/d724ef1ec3ab2125f38a1d53285745445ec4a8f19b9bb0761b4064316679/pyreadline-2.1.zip (109kB)
     |████████████████████████████████| 112kB 1.1MB/s
Installing collected packages: pyreadline
  Running setup.py install for pyreadline ... done
Successfully installed pyreadline-2.1
WARNING: You are using pip version 19.2.3, however version 20.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

3.簡單操作
①接下來,用 pip 試試安裝各種庫:

pip install xlwt
pip install xlrd
pip install six
pip install requests
pip install oauthlib
pip install requests_oauthlib

②其他使用示例

升級pip
python -m pip install -U pip
安裝相關庫
python -m pip install psutil
卸載相關庫
python -m pip uninstall psutil
查看已安裝的庫
python -m pip freeze


免責聲明!

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



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