Installing Python on Mac OS X(在 Mac OS X 上安装 Python)

发布于 2022-04-26 12:35:34 字数 5228 浏览 1123 评论 0

The latest version of Mac OS X, Mavericks, comes with Python 2.7 out of the box.

最新版的 Mac OS X 系统 Mavericks 自带 Python 2.7,可以立即使用。

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 use other third-party Python libraries.

你不需要任何安装和配置就可以使用 Python。话虽如此,在你开始构建实际使用的Python程序之前,我强烈建议你安装在下一节中描述的工具和库。特别的是,你最应该安装 Setuptools,因为它可以让你非常轻易得使用其他第三方 Python 库。

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.

附带自OS X的这个版本的Python是非常利于学习的,但是对开发来说并不友好。附带的版本可能与被认为是最稳定生产版本的官方最新发行版相比已经过时了。

Doing it Right(正确安装Python)

Let’s install a real version of Python.

让我们安装一个真正的Python版本。

Before installing Python, you’ll need to install GCC. GCC can be obtained by downloading XCode, the smaller Command Line Tools (must have an Apple account) or the even smaller OSX-GCC-Installer package.

在安装之前,你需要安装GCC。GCC可以通过下载XCode获取,这是一个很小的命令行工具(必须要有Apple帐号),或者下载更小的OSX-GCC-Installer包。

Note:

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

注意:

如果你已经安装了XCode,不在再安装OSX-GCC-Installer。如果重复了可能会导致难以诊断的问题。

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.

虽然OS X附带了大量的UNIX实用工具,但是熟悉Linux系统的人可能会注意到缺少了一个关键组件:一个像样的包管理工具。Homebrew可以填补空白。

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

为了安装Homebrew,打开Terminal或者你最喜欢的OSX终端模拟器,运行。

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

The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file

这个脚本将会解释,在安装开始之前改变它会编译和提示你。一旦你已经安装Homebrew,将Homebrew目录插入到你的PATH环境变量的最前面。你可以在你的~/.profile文件底部添加以下代码:

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

Now, we can install Python 2.7:

现在我们可以安装Python 2.7:

$ brew install python

This will take a minute or two.

这会花费一到两分钟

Setuptools & Pip(包管理工具)

Homebrew installs Setuptools and pip for you.

Homebrew可以为你安装Setuptoolspip

Setuptools enables you to download and install any compliant Python software over a network (usually the Internet) with a single command (easy_install). It also enables you to add this network installation capability to your own Python software with very little work.

Setuptools可以使你通过网络(通常是Internet)下载和安装任何兼容的Python软件,仅需一条简单的easy_install命令。它也让你通过很少的工作量就可以将这种网络安装能力添加到自己的Python软件中。

pip is a tool for easily installing and managing Python packages, that is recommended over easy_install. It is superior to easy_install in several ways, and is actively maintained.

pip一种轻松安装和管理Python包的工具,比easy_install更受欢迎。它在几个方面优于easy_install,并积极维护。

Virtual Environments(虚拟环境)

A Virtual Environment 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.

Virtual Environment是一种隔离依赖的工具,通过创建虚拟Python环境来保持不同项目在单独的地方。它解决了“项目X依赖版本1.x但是项目Y需要4.x”这种困境,可以保证你的总包目录是干净的和可管理的。

For example, you can work on a project which requires Django 1.3 while also maintaining a project which requires Django 1.0.

例如,你可以在一个依赖Django 1.3的项目上工具,也可以同时维护一个需要Django 1.0的项目。

To start using and see more information: Virtual Environments docs.

开始使用,查看更多信息:Virtual Environments 文档。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

JSmiles

生命进入颠沛而奔忙的本质状态,并将以不断告别和相遇的陈旧方式继续下去。

0 文章
0 评论
84961 人气
更多

推荐作者

醉城メ夜风

文章 0 评论 0

远昼

文章 0 评论 0

平生欢

文章 0 评论 0

微凉

文章 0 评论 0

Honwey

文章 0 评论 0

qq_ikhFfg

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文