zoukankan      html  css  js  c++  java
  • pyenv安装

    pyenv安装

    https://github.com/pyenv/pyenv,这里是github的地址,pyenv是一个类似virtualenv的工具,提供python的多版本环境控制

    安装依赖环境(root用户):

    yum -y install make gcc patch gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel readline-devel

    安装pyenv(普通用户):

    $ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    $ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
    $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
    $ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
    $ exec "$SHELL"

    查看支持的python版本:

    $ pyenv install --list

    安装具体的某个版本:

    [ocean@jenkins ~]$ pyenv install 3.6.2
    Downloading Python-3.6.2.tar.xz...
    -> https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
    Installing Python-3.6.2...
    Installed Python-3.6.2 to /home/ocean/.pyenv/versions/3.6.2
    [root@jenkins ~]# pyenv install 3.5.2
    pyenv: /root/.pyenv/versions/3.5.2 already exists
    continue with installation? (y/N) y
    Downloading Python-3.5.2.tar.xz...
    -> https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
    Installing Python-3.5.2...
    patching file Lib/venv/scripts/posix/activate.fish
    Installed Python-3.5.2 to /root/.pyenv/versions/3.5.2

    查看安装的python版本:

    [ocean@jenkins py362]$ pyenv versions
    * system (set by /home/ocean/py362/.python-version)
      3.5.2
      3.6.2

    ok,简单使用可以查看帮助:

    [ocean@jenkins ~]$ pyenv help
    Usage: pyenv <command> [<args>]
    
    Some useful pyenv commands are:
       commands    List all available pyenv commands
       local       Set or show the local application-specific Python version
       global      Set or show the global Python version
       shell       Set or show the shell-specific Python version
       install     Install a Python version using python-build
       uninstall   Uninstall a specific Python version
       rehash      Rehash pyenv shims (run this after installing executables)
       version     Show the current Python version and its origin
       versions    List all Python versions available to pyenv
       which       Display the full path to an executable
       whence      List all Python versions that contain the given executable
    
    See `pyenv help <command>' for information on a specific command.
    For full documentation, see: https://github.com/pyenv/pyenv#readme

     如何切换python版本呢?

    使用pyenv的local命令:

    [ocean@jenkins ~]$ tree 
    .
    ├── py352
    └── py362
    
    2 directories, 0 files

    我在家目录下分别按照安装的python版本号建立的对应的目录,我们来测试一下:

    [ocean@jenkins ~]$ cd py352/
    [ocean@jenkins py352]$ python -V
    Python 2.7.5

    现在没有执行pyenv的local命令时,python版本是系统默认的2.7.5,然后我们来使用pyenv切换版本:

    [ocean@jenkins py352]$ pyenv local 3.5.2
    [ocean@jenkins py352]$ python -V
    Python 3.5.2

    直接就成了3.5.2,然后我们在退回到py362目录:、

    [ocean@jenkins py352]$ cd ../py362
    [ocean@jenkins py362]$ python -V
    Python 2.7.5
    [ocean@jenkins py362]$ pyenv local 3.6.2
    [ocean@jenkins py362]$ python -V
    Python 3.6.2

    退回到家目录看下:

    [ocean@jenkins py362]$ cd 
    [ocean@jenkins ~]$ python -V
    Python 2.7.5

    还是系统默认的python版本,这样就实现了python版本得切换。

    [ocean@jenkins py362]$ ll /home/ocean/py362 -a
    total 8
    drwxrwxr-x 2 ocean ocean   28 Sep  4 19:08 .
    drwx------ 6 ocean ocean 4096 Sep  4 19:08 ..
    -rw-rw-r-- 1 ocean ocean    6 Sep  4 19:04 .python-version
    [ocean@jenkins py362]$ cat .python-version 
    3.6.2

    pyenv就是通过特定目录下的

    .python-version

    文件来进行python特定版本的切换,删掉该文件就回归到系统默认python程序。

    如果你在某个特定python版本目录下,想使用系统的默认python程序,可以在特定目录下执行:

    $ pyenv local system

     这样就实现了python多版本的任意切换。

    pyenv本地安装:

    #sudo yum -y install git make gcc patch gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel readline-devel
    #第一步:
    git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
    echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
    source ~/.bash_profile
    mkdir ~/.pip
    cat > ~/.pip/pip.conf <<eof
    [global]
    index-url = http://mirrors.aliyun.com/pypi/simple/
    [install]
    trusted-host=mirrors.aliyun.com
    eof
    source ~/.bash_profile
    mkdir ~/Downloads/
    sudo cp /tmp/Python-2.7.5.tgz ~/Downloads/
    cp ~/Downloads/Python-2.7.5.tgz ~/Downloads/8e1b5fa87b91835afb376a9c0d319d41feca07ffebc0288d97ab08d64f48afbf
    cd ~/Downloads/
    python -m SimpleHTTPServer 8000

    #第二步:
    source ~/.bash_profile
    export PYTHON_BUILD_MIRROR_URL="http://127.0.0.1:8000/"
    pyenv install 2.7.5
     

    但是从http的log中发现收到的请求是一个字符串"HEAD /0010f56100b9b74259ebcd5d4b295a32324b58b517403a10d1a2aa7cb22bca40 HTTP/1.1",我们要把Python-2.7.5.tar.xz复制一份到这个字符串为名的文件,然后重启httpserver,最后用pyenv即可安装

    cp ~/Downloads/Python-2.7.5.tgz ~/Downloads/8e1b5fa87b91835afb376a9c0d319d41feca07ffebc0288d97ab08d64f48afbf
    python -m SimpleHTTPServer 8000

    pyenv install 2.7.5

    ########################
    mdkir ~/Downloads/
    cd ~/Downloads/
    python -m SimpleHTTPServer 8000
    export PYTHON_BUILD_MIRROR_URL="http://127.0.0.1:8000/"
    pyenv install 2.7.5

    有时候网速特别不给力,最好下载好python的包本地安装哦。

  • 相关阅读:
    JavaScript 开发进阶:理解 JavaScript 作用域和作用域链
    jquery插件 源码
    webkit浏览器渲染影响因素分析
    JS操作JSON总结
    转:ie6与firefox操作iframe中DOM节点的一点不同
    input:focus
    JS设计模式一:单例模式
    JavaScript 变量、函数与原型链
    让你提前认识软件开发(49):自己主动測试
    Docker 开源管理工具集锦
  • 原文地址:https://www.cnblogs.com/ocean-boy/p/7475922.html
Copyright © 2011-2022 走看看