zoukankan      html  css  js  c++  java
  • mac上Python多版本共存(python2.7.10和python3.5.0)

    本文的实现目标是在mac上安装一个python3.5.0的版本,跟当前系统自带的python2.7.10共存.
    查看当前版本号

    python -V
    2.7.10
    

    安装配置Python版本管理器pyenv

    1. 安装pyenv

    brew install pyenv
    安装过程中,遇到一个一个问题Error: parent directory is world writable but not sticky

    2. 根据提示需要添加变量

    if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
    export PYENV_ROOT=/usr/local/var/pyenv
    

    因为我已经安装了zsh,所以需要在~/.zshrc中将上面的两句加入到文件的末尾,最后执行
    source ~/.zshrc

    3. 查看已经安装了哪些版本的Python

    pyenv versions
    其中版本号前面有*号的就是当前生效的版本,查看当前生效的版本也可以用
    pyenv version

    4. 安装指定版本的Python

    pyenv install 3.5.0
    #安装完成后必须rehash
    pyenv rehash
    

    安装过程中,也是出现报错BUILD FAILED (OS X 10.10.5 using python-build 20160130),解决办法见pyenv BUILD FAILED解决方法

    5. 切换和使用指定的版本Python版本有3种方法

    ➜  ~ pyenv
    pyenv 20150310
    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/yyuu/pyenv#readme
    

    特别建议:

    系统全局用系统默认的Python比较好,不建议直接对其操作
    pyenv global system
    
    用local进行指定版本切换,一般开发环境使用。
    pyenv local 2.7.10
    
    对当前用户的临时设定Python版本,退出后失效
    pyenv shell 3.5.0
    
    取消某版本切换
    pyenv local 3.5.0 --unset
    

    优先级关系:shell——local——global

    #####另外最重要的一点,当执行了pyenv shell/local/global 命令后,一定要执行 source ~/.zshrc ,不然切换版本就不会生效。

    最后执行

    ➜  ~ pyenv versions
      system
    * 3.5.0 (set by PYENV_VERSION environment variable)
    ➜  ~
    ➜  ~ python -V
    Python 3.5.0
    

    参考资料:

    Mac多Python版本共存,多个独立Python开发环境切换

  • 相关阅读:
    tyvj4751 NOIP春季系列课程 H's Problem (树状数组)
    卡牌分组([AtCoder ARC073]Ball Coloring)
    bzoj1036 [ZJOI2008]树的统计Count (树链剖分+线段树)
    bzoj2287 POJ Challenge 消失之物(背包)
    不能建立引用数组
    CString和string的区别
    防止应用程序重复启动
    public,protected,private
    ATL
    c++头文件中定义全局变量
  • 原文地址:https://www.cnblogs.com/mingaixin/p/6295963.html
Copyright © 2011-2022 走看看