How can I install multiple versions of Python on latest OS X and use them in parallel?

后端 未结 5 1438
暖寄归人
暖寄归人 2020-12-05 06:59

I want to run tests with multiple Python versions on OS X 10.11, including:

  • Python 2.6 - ?!
  • Python 2.7 - default - solved
  • Python 3.4 - ?!
5条回答
  •  臣服心动
    2020-12-05 07:30

    pyenv is the thing you want. It works very very well:

    pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python.

    https://github.com/pyenv/pyenv

    Install it via Homebrew:

    $ brew update
    $ brew install pyenv
    

    It handles the download, compilation, and installation of various pythons for you, e.g.:

    $ pyenv install 3.7.2
    

    It can show you which versions you've installed, and which is active:

    $ pyenv versions
      system
      3.6.7
    * 3.7.2
    

    When you're in a new project directory, just tell pyenv which python version to use there:

    $ pyenv local 3.6.7  # Because e.g. tensorflow isn't compat. with 3.7 :-(
    

    You can set a 'default' version everywhere else:

    $ pyenv global 3.7.2
    

提交回复
热议问题