美文网首页
linux 中安装pyenv

linux 中安装pyenv

作者: 天天向上_ac78 | 来源:发表于2019-07-10 22:31 被阅读0次

    pyenv 的定义

    python virtual environment
    官方文档:https://github.com/pyenv/pyenv

    pyenv 安装步骤

    linux 环境脚本安装

    yum install -y git
    curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
    

    将如下3行加入.bash_profile。 如果没有文件,在当前用户家目录下新建

    export PATH="~/.pyenv/bin:$PATH"
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
    

    运行

    source ~/.bash_profile
    

    执行 pyenv version 出现下面界面表示成功

    bash-3.2$ pyenv version
    system (set by /Users/litianzeng/.pyenv/version)
    

    安装依赖包

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

    Mac 环境

    1. 下载pyenv 的代码到~/.pyenv目录下
    git clone https://github.com/yyuu/pyenv.git ~/.pyenv
    
    1. 添加环境变量
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
    
    1. 启动shell 的时候,使初始化pyenv
    eval "$(pyenv init -)" >> ~/.bash_profile
    eval "$(pyenv virtualenv-init -)" >> ~/.bash_profile
    
    1. 新启动shell,以使路径更改生效
    source ~/.bash_profile
    

    如果不想使用中出现莫名其妙的问题,要求安装的环境

    xcode-select --install
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    brew install openssl readline sqlite3 xz zlib 
    

    运行Mojave或更高版本(10.14+)时,您还需要安装其他SDK标头:

    sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
    
    

    其它系统环境的问题,在https://github.com/pyenv/pyenv/wiki查找即可。

    pyenv的使用

    1. pyenv install --list
      查询所有可以安装的版本:
    bash-3.2$ pyenv install --list
    Available versions:
      2.1.3
      ...
      ...
      
      3.7.2
      3.8-dev
    

    2 pyenv install xxx
    安装所需的版本:

    pyenv install 3.7.2 , 安装3.7.2版本
    
    1. pyenv version 显示当前活动的Python版本
      pyenv versions 显示当前pyenv 的所有可用版本
    litianzengdeMacBook-Pro:~ litianzeng$ pyenv version
    system (set by /Users/litianzeng/.pyenv/version)
    litianzengdeMacBook-Pro:~ litianzeng$ pyenv versions
    * system (set by /Users/litianzeng/.pyenv/version)
    
    1. pyenv uninstall 3.6.2
      卸载python版本
    pyenv uninstall 3.6.2
    
    1. pyenv virtualenv 3.6.8 python3,
      安装3.6.8的虚拟环境,名字是python3
    bash-3.2$ pyenv virtualenv 3.6.8 pyhon3
    Looking in links: /var/folders/y1/d996r6vs08l0k8ng5gxm2_2w0000gn/T/tmpzd3sxt1g
    Requirement already satisfied: setuptools in /Users/litianzeng/.pyenv/versions/3.6.8/envs/pyhon3/lib/python3.6/site-packages (40.6.2)
    Requirement already satisfied: pip in /Users/litianzeng/.pyenv/versions/3.6.8/envs/pyhon3/lib/python3.6/site-packages (18.1)
    

    6 . pyenv local python3
    将当前目录切换到python3环境

    pyenv local python3
    
    1. pyenv uninstall python3
      删除python3 环境
    pyenv uninstall python3
    
    1. pyenv global system , 将全局版本切换成system 版本
    2. pyenv shell system, 将当前shell 切换到system 版本
    3. 优先级
      pyenv shell > pyenv local > pyenv global

    坑:

    ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib
    官方已经给出解决方案:https://github.com/pyenv/pyenv/wiki/Common-build-problems#error-the-python-ssl-extension-was-not-compiled-missing-the-openssl-lib

    在Mac上且用homebrew装了openssl的情况下,命令行如下:

    CFLAGS="-I$(brew --prefix openssl)/include" \
    LDFLAGS="-L$(brew --prefix openssl)/lib" \
    pyenv install -v 3.6.2
    

    相关文章

      网友评论

          本文标题:linux 中安装pyenv

          本文链接:https://www.haomeiwen.com/subject/sglbyqtx.html