python source install

python源码编译

  1. python install

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [root@localhost app]# xz -d Python-2.7.13.tar.xz
    [root@localhost app]# tar xf Python-2.7.13.tar
    [root@localhost Python-2.7.13]# ./configure --enable-optimizations --prefix=/mnt/app/python.2.7.13
    [root@localhost Python-2.7.13]# make -j 4
    [root@localhost Python-2.7.13]# make -j 4 install

    [root@localhost Python-2.7.13]# ln -s /mnt/app/python.2.7.13 /mnt/app/python

    补充: python升级版本后,yum不可用,解决方法:
    CentOS6:
    [root@localhost Python-2.7.13]# sed -i s/python/python2.6/g /usr/bin/yum
    CentOS7:
    [root@localhost Python-2.7.13]# sed -i s/python/python2.7/g /usr/bin/yum
    [root@localhost Python-2.7.13]# sed -i s/python/python2.7/g /usr/libexec/urlgrabber-ext-down
  2. pip install

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [root@localhost Python-2.7.13]# wget https://bootstrap.pypa.io/get-pip.py
    [root@localhost Python-2.7.13]# /mnt/app/python/bin/python get-pip.py
    [root@localhost Python-2.7.13]# /mnt/app/python/bin/pip -V

    [root@localhost Python-2.7.13]# mkdir ~/.pip
    [root@localhost Python-2.7.13]# cat > ~/.pip/pip.conf <<EOF
    [global]
    trusted-host=mirrors.aliyun.com
    index-url=http://mirrors.aliyun.com/pypi/simple/
    [list]
    format=columns
    EOF
  3. virtualenv install

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [root@localhost Python-2.7.13]# /mnt/app/python/bin/pip install virtualenv
    [root@localhost Python-2.7.13]# /mnt/app/python/bin/virtualenv -p /mnt/app/python/bin/python /mnt/web/myenv
    Already using interpreter /mnt/app/python/bin/python
    New python executable in /mnt/web/myenv/bin/python
    Installing setuptools, pip, wheel...done.

    [root@localhost Python-2.7.13]# source /mnt/web/myenv/bin/activate
    (myenv) [root@localhost Python-2.7.13]# pip -V
    pip 9.0.1 from /mnt/web/myenv/lib/python2.7/site-packages (python 2.7)
    (myenv) [root@localhost Python-2.7.13]# deactivate

    [root@localhost Python-2.7.13]# rm -rf /mnt/web/myenv