Installing Python 2 on Mac OS X

../../_images/34435688560_4cc2a7bcbb_k_d.jpg

Mac OS X comes with Python 2.7 out of the box.

You do not need to install or configure anything else to use Python. Having said that, I would strongly recommend that you install the tools and libraries described in the next section before you start building Python applications for real-world use. In particular, you should always install Setuptools, as it makes it much easier for you to install and manage other third-party Python libraries.

The version of Python that ships with OS X is great for learning, but it's not good for development. The version shipped with OS X may be out of date from the official current Python release, which is considered the stable production version.

바로 시작하기

진짜 파이썬을 설치해보자!

Before installing Python, you'll need to install a C compiler. The fastest way is to install the Xcode Command Line Tools by running xcode-select --install. You can also download the full version of Xcode from the Mac App Store, or the minimal but unofficial OSX-GCC-Installer package.

주석

If you already have Xcode installed, do not install OSX-GCC-Installer. In combination, the software can cause issues that are difficult to diagnose.

주석

If you perform a fresh install of Xcode, you will also need to add the commandline tools by running xcode-select --install on the terminal.

While OS X comes with a large number of Unix utilities, those familiar with Linux systems will notice one key component missing: a decent package manager. Homebrew fills this void.

To install Homebrew, open Terminal or your favorite OS X terminal emulator and run

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

이 스크립트는 설치가 시작되기 전에 설치로 인해 변경되는 것들과 명령어를 알려줍니다. Homebrew가 설치됐으면 Homebrew 디렉토리를 PATH 환경 변수의 최상단에 넣으세요. ~/.profile 파일의 마지막 줄에 다음과 같이 덧붙이면 됩니다.

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

이제 우리는 파이썬 2.7을 설치할 수 있습니다.

$ brew install python@2

Because python@2 is a "keg", we need to update our PATH again, to point at our new installation:

export PATH="/usr/local/opt/python@2/libexec/bin:$PATH"

Homebrew names the executable python2 so that you can still run the system Python via the executable python.

$ python -V   # Homebrew installed Python 3 interpreter (if installed)
$ python2 -V  # Homebrew installed Python 2 interpreter
$ python3 -V  # Homebrew installed Python 3 interpreter (if installed)

Setuptools & Pip

Homebrew는 Setuptools 과 pip 를 설치해줍니다.

Setuptools는 네트워크 상에서(보통은 인터넷) 단 한 줄의 명령어(easy_install)로 파이썬 소프트웨어를 다운로드받고 설치할 수 있도록 해줍니다. 또한 최소한의 작업으로 당신이 만든 파이썬 소프트웨어의 네트워크 설치를 가능하게 해줍니다.

pip 는 파이썬 패키지를 손쉽게 설치하고 관리할 수 있게 해주는 툴입니다. easy_install 로 설치할 것을 추천한다. easy_install많은 면 에서 탁월하고, 활발히 운영되고 있습니다.

$ pip2 -V  # pip pointing to the Homebrew installed Python 2 interpreter
$ pip -V  # pip pointing to the Homebrew installed Python 3 interpreter (if installed)

Virtual Environments

A Virtual Environment (commonly referred to as a 'virtualenv') is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the "Project X depends on version 1.x but, Project Y needs 4.x" dilemma, and keeps your global site-packages directory clean and manageable.

예를 들면 장고 1.10을 쓰는 프로젝트에서 일하면서, 장고 1.8을 사용하는 프로젝트를 유지보수 할 수 있도록 해줍니다.

Virtual Environments을 사용하기 위해 더 많은 정보를 알고 싶다면 Virtual Environments 문서에서 볼 수 있습니다.


This page is a remixed version of another guide, which is available under the same license.