14

在 Mac OS X 10.6 Snow Leopard 上安装 Mercurial

我使用以下命令在 Mac OS X 10.6 Snow Leopard 上安装了 Mercurial 1.3.1:

cd ~/src
curl -O https://www.mercurial-scm.org/release/mercurial-1.3.1.tar.gz
tar -xzvf mercurial-1.3.1.tar.gz
cd mercurial-1.3.1
make all
sudo make install

这会将 Mercurial 的站点包文件安装在/usr/local/lib/python2.6/site-packages/. 我知道从 Mac 磁盘映像安装 Mercurial 会将文件安装到/Library/Python/2.6/site-packages/中,这是 Mac OS X 默认 Python 安装的 site-packages 目录。

我将 Python 2.6.2+ 作为框架安装,其站点包目录位于:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

以这种方式安装 Mercurial 后,我必须发出:

PYTHONPATH=/usr/local/lib/python2.6/site-packages:"${PYTHONPATH}"

为了让 Mercurial 工作。

问题

  • 如何使用不同目录中的站点包从源代码安装 Mercurial?
  • 在当前位置拥有站点包有优点还是缺点?在已经存在的 Python 站点包目录之一中会更好吗?
  • 自从我修改了 PYTHONPATH (或与此相关的任何其他冲突)后,我是否需要担心 virtualenv 是否正常工作?

从源代码安装的原因

Hivelogic的Dan Benjamin在他的文章在 Snow Leopard 上安装 Mercurial中提供了从源代码安装 Mercurial 的好处和说明。

4

5 回答 5

13

为什么需要使用macports?pythoneasy_install是最简单的方法并且没有错误:

easy_install -U mercurial

一直都是简单的金子弹。

于 2010-04-02T05:11:21.367 回答
8

特别是因为您有 Python 2.6 可用,您可以执行类似的操作python setup.py install --user,它将安装 Mercurial,并以 ~/.local 作为前缀。您不必为此更改 PYTHONPATH,只需将 ~/.local/bin 添加到您的 PATH 中。

关于优点和缺点:这一切都取决于您的 PYTHONPATH 通常看起来像什么,因为修改它自然会修改包的加载顺序(如果您安装了一个带有一个前缀的 Mercurial 版本和另一个带有不同前缀的版本,这将变得相关)。通常,我尝试将所有自定义包放入某个站点包文件夹(例如 /usr/local/lib/python2.6/site-packages)。再说一遍:如果你是唯一会使用这些库的人,那么 Python 2.6 的 distutils 提供的 --user 标志使这样的事情变得非常容易(将 ~/.local 添加到模块的默认搜索路径中)。

只要您始终使用 PYTHONPATH,virtualenv 应该可以正常工作。

于 2009-09-22T21:08:11.820 回答
8

将 mercurial - 或任何一般的 Python 包 - 安装到您的用户主目录中。因此,您可以从任何 Python(相同版本)或任何 virtualenv 访问它们。有关详细信息,请参阅PEP 370

$ cd mercurial-x.y.z/
$ python2.6 setup.py install --user
$ ~/.local/bin/hg
...

但是为什么要手动构建 mercurial?我使用macports

$ sudo port install mercurial
$ which hg
/opt/local/bin/hg

更新:如今,我只是使用PyPM将 mercurial 安装到~/.local/bin/hg.

于 2009-09-29T05:28:44.530 回答
5

正如 Sridhar 所建议的,macports 在多个架构和版本的 MacOsX + 上运行良好,允许更新等等:

$ port variants mercurial
mercurial has the variants:
   bash_completion: Completion support for bash
   zsh_completion: Install mercurial zsh completion file
$

以便您可以使用:

$ sudo port install mercurial +bash_completion
--->  Computing dependencies for mercurial
--->  Fetching mercurial
--->  Attempting to fetch mercurial-1.3.1.tar.gz from http://arn.se.distfiles.macports.org/python
--->  Attempting to fetch mercurial-1.3.1.tar.gz from http://www.selenic.com/mercurial/release/
--->  Verifying checksum(s) for mercurial
--->  Extracting mercurial
--->  Configuring mercurial
--->  Building mercurial
--->  Staging mercurial into destroot
--->  Installing mercurial @1.3.1_0+bash_completion
--->  Activating mercurial @1.3.1_0+bash_completion
--->  Cleaning mercurial
$
于 2009-12-24T11:47:24.377 回答
1

All those answers look complicated to the average mac OS X users, because they are specific to other install platforms. As of now the Mercurial website offers an installer package (compressed as a zip file).

于 2010-05-04T01:52:07.000 回答