Use pyenv and pyenv-virtualenv in mac to manage multiple versions of python.

Source: Internet
Author: User
Tags install homebrew rehash virtualenv

Use pyenv and pyenv-virtualenv in mac to manage multiple versions of python.
0. System Version

Angel :~ $ More/System/Library/CoreServices/SystemVersion. plist

<? Xml version = "1.0" encoding = "UTF-8"?>

<! DOCTYPE plist PUBLIC "-// Apple // dtd plist 1.0 // EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<Plist version = "1.0">

<Dict>

<Key> ProductBuildVersion </key>

<String> 14C109 </string>

<Key> ProductCopyright </key>

<String> 1983-2015 Apple Inc. </string>

<Key> ProductName </key>

<String> Mac OS X </string>

<Key> ProductUserVisibleVersion </key>

<String> 10.10.2 </string>

<Key> ProductVersion </key>

<String> 10.10.2 </string>

</Dict>

</Plist>


1. Install homebrew

Open the terminal and enter the following command to install homebrew.

Angel :~ $ Ruby-e "$ (curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"

Test whether the installation is successful

Angel :~ $ Brew-v

Homebrew 0.9.5


Indicates that the installation is successful.

Reference http://brew.sh/index_zh-cn.html

2. Install pyenv and pyenv-virtualenv

Angel :~ $ Brew install pyenv

Angel :~ $ Brew install pyenv-virtualenv

Verify whether the installation is successful

Angel :~ $ Pyenv-v

Python 20150326

Angel :~ $ Pyenv-virtualenv -- version

/Usr/local/bin/pyenv-virtualenv: line 127: pyenv-prefix: command not found

/Usr/local/bin/pyenv-virtualenv: line 130: pyenv-prefix: command not found

Pyenv-virtualenv 20150119 (virtualenv unknown)

Pyenv is successfully installed. If pyenv-virtualenv is abnormal, skip this step. (The reason is not investigated, but it does not affect subsequent use. If you have any questions, contact us ).

3. view the python version that can be installed in pyenv install -- list

Angel :~ $ Pyenv install -- list

Available versions:

2.7

2.7.1

2.7.2

2.7.3

2.7.4

2.7.5

2.7.6

2.7.7

2.7.8

2.7.9

... (Due to space issues, 3000 words are omitted here)

3.4.2

3.4.3

3.5.0a1

3.5.0a2

3.5-dev


4. Install the corresponding python version

Angel :~ $ Pyenv install 3.4.3

Pyenv:/Users/angel/. pyenv/versions/3.4.3 already exists

Continue with installation? (Y/N) N

My computer has been installed with 3.4.3...

Use pyenv versions to view the python version currently in use. The preceding asterisk (*) indicates the current python version (3.4.3)

Angel :~ $ Pyenv versions

System

* 3.4.3 (set by/Users/angel/. pyenv/version)

Reference http://v2in.com/pyenv-installation-and-usage.html

Http://seisman.info/python-pyenv.html

5. Set the environment

Add the following content to. bashrc (or. bash_profile ):

You can generate one file without the preceding two files.

If which pyenv>/dev/null; then eval "$ (pyenv init-)"; fi

If which pyenv-virtualenv-init>/dev/null; then eval "$ (pyenv virtualenv-init-)"; fi

6. Switch python version back and forth in pyenv global

Angel :~ $ Python

Python 3.4.3 (default, May 2 2015, 21:56:04)

[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.49)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> Exit ()

Angel :~ $ Pyenv versions

System

* 3.4.3 (set by/Users/angel/. pyenv/version)

Angel :~ $ Pyenv global system

Angel :~ $ Python

Python 2.7.6 (default, Sep 9 2014, 15:04:36)

[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> Exit ()

Angel :~ $ Pyenv versions

* System (set by/Users/angel/. pyenv/version)

3.4.3

Angel :~ $ Pyenv versions

"System" is the default system version.

7. pyenv virtualenv create a virtual python Environment

Angel :~ $ Pyenv virtualenv 3.4.3 myvenv

Ignoring indexes: https://pypi.python.org/simple

Requirement already satisfied (use -- upgrade to upgrade): setuptools in/Users/angel/. pyenv/versions/myvenv/lib/python3.4/site-packages

Requirement already satisfied (use -- upgrade to upgrade): pip in/Users/angel/. pyenv/versions/myvenv/lib/python3.4/site-packages


Angel :~ $ Pyenv virtualenvs 'view python Virtual Environment

Myvenv (created from/Users/angel/. pyenv/versions/3.4.3)

Angel :~ $ Pyenv versions

* System (set by/Users/angel/. pyenv/version)

3.4.3

Myvenv

Angel :~ $ Pyenv shell myvenv

Pyenv-virtualenv: activate myvenv

(Myvenv) angel :~ $ Python

Python 3.4.3 (default, May 2 2015, 21:56:04)

[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.49)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> Exit ()

(Myvenv) angel :~ $ Pyenv versions

System

3.4.3

* Myvenv (set by PYENV_VERSION environment variable)

Finally, you can use pyenv-h and pyenv commands to view pyenv commands.

Angel :~ $ Pyenv commands

-- Version

Activate

Commands

Completions

Deactivate

Exec

Global

Help

Hooks

Init

Install

Local

Prefix

Rehash

Root

Shell

Shims

Uninstall

Version

Version-file

Version-file-read

Version-file-write

Version-name

Version-origin

Versions

Virtualenv

Virtualenv-init

Virtualenv-prefix

Virtualenvs

Whence

Which

Angel :~ $ Pyenv-h

Python 20150326

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

Test photos http://tbb.co/managing-python-on-os-x-with-pyenv/

Good night!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.