1.國內鏡像源python
阿里雲 http://mirrors.aliyun.com/pypi/simple/
豆瓣http://pypi.douban.com/simple/
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
華中科技大學http://pypi.hustunique.com/ubuntu
臨時使用:windows
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
永久修改:bash
Linux下:修改 ~/.pip/pip.conf (沒有就建立一個文件夾及文件。文件夾要加「.」,表示是隱藏文件夾)
內容以下:ide
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn測試
windows下:直接在user目錄中建立一個pip目錄,如:C:\Users\xx\pip,而後新建文件pip.ini,即 %HOMEPATH%\pip\pip.ini,在pip.ini文件中輸入如下內容(以豆瓣鏡像爲例):ui
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com阿里雲
2.搭建本地源url
首先使用pip下載全部須要的python包到指定的目錄內,好比/python-packagesspa
pip download -d /python-packages -r requirement.txt #pip-requires.txt爲須要下載的python包列表
運行腳本init_local_pip.sh /python-packages
#!/bin/bash # set -x if [ $# -ne 1 ]; then echo "Usage: $0 packages_dir" exit 1 fi [ ! -d $1 ] && echo "Error: you should provide a directory." && exit 1 dest=$1 dest=${dest%/} if ! echo $dest |grep -q "^/"; then echo "Error: please use the absolute path." exit 1 fi if ! ls $dest | egrep -q "(gz|zip)$"; then echo "Note: nothing need to do." exit 0 fi #--------------------------------------------- TOPDIR=$(cd $(dirname "$0") && pwd) tmpdir=`mktemp -d` #--------------------------------------------- for i in `ls ${dest}/{*.gz,*.zip} 2>/dev/null` do rm -rf $tmpdir/* cp $i $tmpdir cd $tmpdir package_arch_name=`ls` if echo $package_arch_name | grep -q "gz$"; then tar xf $package_arch_name gz_suffix=1 else unzip $package_arch_name gz_suffix=0 fi rm -rf $package_arch_name package_name=`ls` cd $package_name if ls |grep -q "egg-info"; then python setup.py egg_info python setup.py build cd .. if [ $gz_suffix -eq 1 ]; then tar czf $package_arch_name $package_name else zip -r $package_arch_name $package_name fi rm -rf $i cp $package_arch_name $dest/ fi cd $TOPDIR done rm -rf $tmpdir
安裝pypiserver
pip install pypiserver
爲了讓在系統啓動的時候同時啓動pypiserver,修改/etc/rc.local
cat /etc/rc.local |egrep -v "^#|^$" pypi-server /python-packages &>/var/log/pypi-server.log & exit 0
啓動pypiserver
bash /etc/rc.local
測試
再打開一個虛擬機,ip設置爲172.16.1.2,並指定pip源爲172.16.1.1
root@ubuntu:~# cat .pip/pip.conf
[global]
trusted-host = 172.16.1.1
index-url = http://172.16.1.1:8080/simple
2.用pip安裝所需python包便可
root@ubuntu:~# pip install -r pip-requires 原文連接:https://blog.csdn.net/wjciayf/article/details/53813493