python,生产环境安装

国内镜像源
    pypi:
        清华大学  https://pypi.tuna.tsinghua.edu.cn/simple
        中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple
        阿里云 http://mirrors.aliyun.com/pypi/simple
        中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple
        豆瓣 (douban) http://pypi.douban.com/simple
    python:
        http://mirrors.sohu.com/python
    rpm :
        ftp://rpmfind.net/linux/epel/7/x86_64/Packages/c/
        http://mirrors.sohu.com/centos/7/os/x86_64/Packages/
    下载使用镜像源下载某个文件:
        pip install tensorflow==1.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

生产环境安装

1 判断是否已安装gcc
    问题1.configure: error: no acceptable C compiler found in $PATH
    解决:安装 gcc
        推荐使用 CentOS7(64)环境使用rpm命令安装gcc,教程:https://blog.csdn.net/q5983901/article/details/88618500


2. 下载 python 包,国内镜像网址
     http://mirrors.sohu.com/python

3. ./configure  --prefix=/opt/python36/  
    

4 make && make install

5 ./Modules/zlibmodule.c:10:18: fatal error: zlib.h: No such file or directory
    安装zlib 包:
        wget http://www.zlib.net/zlib-1.2.11.tar.gz
        进行编译:./configure
        进行安装:make and make install
6 如果出现 5错误,请安装 zlib 后执行 4

7 安装成功

8 设置软连接
    ln -s /opt/python36/bin/python3 /usr/bin/python3
    
    
9 python3 可以使用

10 虚拟环境
    创建:python3 -m venv 文件夹名
    激活:source 文件夹名/bin/activate
    退出:deactivate
    删除:rm -rf 文件夹名

11 安装项目依赖
    打包项目的依赖清单
        只打包当前项目的依赖清单
            pip3 install pipreqs
            pipreqs ./      # 生成项目清单 requirements.txt
        有虚拟环境时,这里打包了虚拟环境所有的包
             freeze > requirements.txt
    
        
    安装依赖包:
        联网:
            pip install -r requirements.txt #联网下载安装
        离线安装:
            # 这里需要保证你下载的环境与将要安装的环境尽量保持一致,因为这样下载的包是按你当前的环境下载,如 下载环境是 mac 部署环境是linux,这里可能会在安装时有些mac包安装不了
            # Could not find a version that satisfies the requirement kiwisolver>=1.0.1 (from matplotlib==2.2.3->-r requirements.txt (line 2)) (from versions: )
No matching distribution found for kiwisolver>=1.0.1 (from matplotlib==2.2.3->-r requirements.txt (line 2))
            # 上面就是因为包不适用安装环境的报错
            # 在本地将项目的依赖下载到 packages文件夹:
            pip download -d packages/ -r requirements.txt
            pip3 install --no-index --find-links=packages_kg/ -r requirements.txt
    
    
12. Could not fetch URL https://pypi.org/simple/jinja2/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/jinja2/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
    出现了openssl问题
    问题出现:当我用pip去安装依赖时报错了,环境是生产环境,openssl安装很乱,我么有找到完整的安装路径,所以我在花费了很长时间去解决问题,
    然而最终还是只能乖乖的去重新安装了openssl 并且问题解决了
    
    解决方案: 1.修改文件 2.重新安装openssl
    
    修改文件: Python-3.6.8/Modules/Setup
        放开下面5行
        # Socket module helper for socket(2)
        _socket socketmodule.c   # 放开这行
        # Socket module helper for SSL support; you must comment out the other
        # socket line above, and possibly edit the SSL variable:
        SSL=/usr/local/ssl
        _ssl _ssl.c
            -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl
            -L$(SSL)/lib -lssl -lcrypto
    开始重新安装 openssl
    下载:wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
     ./config
     make
     make install
     默认安装位置     /usr/local/ssl
    ---------------------------------
    openssl_devel:http://mirror.centos.org/centos/6/os/x86_64/Packages/openssl-devel-1.0.1e-57.el6.x86_64.rpm
    zlib-devel:http://mirror.centos.org/centos/7/os/x86_64/Packages/zlib-devel-1.2.7-18.el7.x86_64.rpm
    krb5-devel:http://mirror.centos.org/centos/7/os/x86_64/Packages/krb5-devel-1.15.1-46.el7.x86_64.rpm
    这些看情况安装
    ---------------------------------

原文地址:https://www.cnblogs.com/liangxinxinbo/p/12936402.html