使用MacPorts和Homebrew都需要预装XCode Command Line Tools,即意味着还需要提前预装XCode。(根据官方文档来看,Fink安装比较新的工具包时,因为提前编译完成所以无需依赖XCode,但对于一些不是二进制的包,如果需要本地编译,还是需要依赖XCode。换而言之,如果想在OS中编译源码,都需要XCode提供支持。)
$ port search python | grep pip
Lightweight pipelining: using Python functions as pipeline jobs.
py-pip @1.5.4 (python, www)
py-pipedream @0.2.0_1 (python)
python module for easy communication over pipes
Plumbum (Latin for lead, which was used to create pipes back in the day) is a small yet feature-rich library for shell script-like programs in Python.
py24-pipedream @0.2.0_1 (python)
python module for easy communication over pipes
py25-pip @1.3.1_1 (python, www)
Lightweight pipelining: using Python functions as pipeline jobs.
py26-pip @1.5.4 (python, www)
Lightweight pipelining: using Python functions as pipeline jobs.
py27-pip @1.5.4 (python, www)
Plumbum (Latin for lead, which was used to create pipes back in the day) is a small yet feature-rich library for shell script-like programs in Python.
py31-pip @1.5.4 (python, www)
Lightweight pipelining: using Python functions as pipeline jobs.
py32-pip @1.5.4 (python, www)
Lightweight pipelining: using Python functions as pipeline jobs.
py33-pip @1.5.4 (python, www)
Plumbum (Latin for lead, which was used to create pipes back in the day) is a small yet feature-rich library for shell script-like programs in Python.
py34-pip @1.5.4 (python, www)
Plumbum (Latin for lead, which was used to create pipes back in the day) is a small yet feature-rich library for shell script-like programs in Python.
$ which python
/usr/bin/python
这是因为你尚未设置默认启用的python和pip文件。需要启用某个版本的程序可以通过port select命令来查看和选择,想了解select命令可以使用$man port进行查看。
$ man port
...
select
For a given group, selects a version to be the default by creating appropriate symbolic links. For instance, python might be linked to python2.6. Available select groups are installed as subdi-
rectories of ${prefix}/etc/select/. To list the available versions in a group, use --list. To see which version is currently selected for a group, use --show. To change the selected version for
a group, use --set.
For example:
port select --list python
port select --show gcc
port select --set gcc mp-gcc44
...
MacPorts会对不同版本的同一个程序进行分组,每个版本都有一个专属的名称,通过指定组名和专属名称就可以启用特定版本的程序。
让我们看一下python的分组:
$ port select --list python
Available versions for python:
none (active)
python25-apple
python26-apple
python27
python27-apple
现在我们启用刚安装的python27,这需要sudo权限:
$ port select --set python python27
Selecting 'python27' for 'python' failed: could not create new link "/opt/local/bin/python" pointing to "/opt/local/bin/python2.7": permission denied
$ sudo port select --set python python27
Password:
Selecting 'python27' for 'python' succeeded. 'python27' is now active.
$ port select --list python
Available versions for python:
none
python25-apple
python26-apple
python27 (active)
python27-apple
$ which python
/opt/local/bin/python
$ python
Python 2.7.6 (default, Nov 18 2013, 15:12:51)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
可以看到第一次没有sudo权限,操作失败。设置成功后会显示python27处于激活状态。同理,启用pip:
$ port select --list pip
Available versions for pip:
none (active)
pip27
$ sudo port select --set pip pip27
Selecting 'pip27' for 'pip' succeeded. 'pip27' is now active.
$ port select --list pip
Available versions for pip:
none
pip27 (active)
$ pip
Usage:
pip <command> [options]
Commands:
install Install packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
zip DEPRECATED. Zip individual packages.
unzip DEPRECATED. Unzip individual packages.
bundle DEPRECATED. Create pybundles.
help Show help for commands.
General Options:
-h, --help Show help.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output.
--log-file <path> Path to a verbose non-appending log, that only logs failures. This log is active by default at /Users/Xavier/.pip/pip.log.
--log <path> Path to a verbose appending log. This log is inactive by default.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
--cert <path> Path to alternate CA bundle.