最近在搭建python环境时遇到断网的情况,往往模块下载到一半就停了,虽然换成国内的镜像也可以勉强解决问题,但是还是升起了搭建一个本地的pip源,不怕断网。
步骤如下:
1.安装python 3.5.4
2.安装pip2pi
pip install pip2pi
3.安装nginx
yum install nginx
    可能会遇到错误说
    
     
      没有可用软件包
      
       nginx
      
     
    
   
    解决方案:(参考
    
     https://www.cnblogs.com/jackylee92/p/6371366.html
    
    )
   
安装epel;
    去epel官网:
    
     http://fedoraproject.org/wiki/EPEL
    
    下载;这里面东西有点多难找;
   
直接贴出下载的地址http://dl.fedoraproject.org/pub/在这里面找;
我的是centos7 64位;在目录中http://dl.fedoraproject.org/pub/epel/7/x86_64/e/
下载正确版本epel的地址为:http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
下载后安装rpm -ivh epel-release-7-9.noarch.rpm
    
   
安装成功后执行yum install nginx即可;
4.配置nginx
    server {
    
    
    listen       80 default_server;
    
    listen       [::]:80 default_server;
    
    server_name  _;
    
    root /opt/python/soft/pypi;
   
include /etc/nginx/default.d/*.conf;
    location / {
    
    
    autoindex on;
    
    }
   
    error_page 404 /404.html;
    
    location = /40x.html {
    
    
    }
   
    error_page 500 502 503 504 /50x.html;
    
    location = /50x.html {
    
    
    }
    
    }
   
5.下载模块
[root@localhost docker] pip2tgz ‘/opt/python/soft/pypi’ -r ‘/home/docker/packages/requirements.txt’
6.建立索引
[root@localhost docker] dir2pi /opt/python/soft/pypi/
    7.启动nginx
    
    [root@localhost docker] nginx
   
     
   
    8.使用本地pip源
    
    pip install –no-cache-dir -i http://127.0.0.1/simple –trusted-host 127.0.0.1 -r requirements.txt
    
    参考:
    
     Python环境下使用pip2pi搭建属于自己的pip源
    
   
 
