解决办法:

$ sudo chown -R $USER /usr/local/lib/python2.
$ pip install mock --ignore-installed six --user

问题:安装mock时报错:

(venv)➜  test git:(master) pip install mock
Requirement already satisfied: mock in /Library/Python/2.7/site-packages
Collecting six>=1.9 (from mock)
Using cached six-1.11.-py2.py3-none-any.whl
Requirement already satisfied: funcsigs>=; python_version < "3.3" in /Library/Python/2.7/site-packages (from mock)
Requirement already satisfied: pbr>=0.11 in /Library/Python/2.7/site-packages (from mock)
Installing collected packages: six
Found existing installation: six 1.4.
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line , in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line , in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line , in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line , in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line , in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line , in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line , in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line , in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line , in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno ] Operation not permitted: '/var/folders/pk/7yrbjrzx0j76mvd9s49djz_40000gn/T/pip-ogx4a9-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

参考:https://github.com/donnemartin/haxor-news/issues/54

pip install --ignore-installed six

又报错:

(venv)➜  test git:(master) pip install mock --ignore-installed six
Collecting mock
Using cached mock-2.0.-py2.py3-none-any.whl
Collecting six
Using cached six-1.11.-py2.py3-none-any.whl
Collecting funcsigs>=; python_version < "3.3" (from mock)
Using cached funcsigs-1.0.-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock)
Using cached pbr-3.1.-py2.py3-none-any.whl
Installing collected packages: six, funcsigs, pbr, mock
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line , in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line , in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line , in install
**kwargs
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line , in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line , in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip/wheel.py", line , in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip/wheel.py", line , in clobber
shutil.copyfile(srcfile, destfile)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line , in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno ] Permission denied: '/Library/Python/2.7/site-packages/six.py'

参考:https://github.com/pypa/pip/issues/4186

pip install mock --ignore-installed six --user

又遇到错误:

Collecting mock
Using cached mock-2.0.-py2.py3-none-any.whl
Collecting six
Using cached six-1.11.-py2.py3-none-any.whl
Collecting funcsigs>=; python_version < "3.3" (from mock)
Using cached funcsigs-1.0.-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock)
Using cached pbr-3.1.-py2.py3-none-any.whl
Installing collected packages: six, funcsigs, pbr, mock
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line , in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line , in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line , in install
**kwargs
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line , in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line , in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip/wheel.py", line , in move_wheel_files
maker.make_multiple(['%s = %s' % kv for kv in console.items()])
File "/Library/Python/2.7/site-packages/pip/_vendor/distlib/scripts.py", line , in make_multiple
filenames.extend(self.make(specification, options))
File "/Library/Python/2.7/site-packages/pip/_vendor/distlib/scripts.py", line , in make
self._make_script(entry, filenames, options=options)
File "/Library/Python/2.7/site-packages/pip/_vendor/distlib/scripts.py", line , in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "/Library/Python/2.7/site-packages/pip/_vendor/distlib/scripts.py", line , in _write_script
self._fileop.write_binary_file(outname, script_bytes)
File "/Library/Python/2.7/site-packages/pip/_vendor/distlib/util.py", line , in write_binary_file
with open(path, 'wb') as f:
IOError: [Errno ] Permission denied: '/usr/local/bin/pbr'

最后:

(venv)➜  test git:(master) pip install mock --ignore-installed six --user
Collecting mock
Using cached mock-2.0.-py2.py3-none-any.whl
Collecting six
Using cached six-1.11.-py2.py3-none-any.whl
Collecting funcsigs>=; python_version < "3.3" (from mock)
Using cached funcsigs-1.0.-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock)
Using cached pbr-3.1.-py2.py3-none-any.whl
Installing collected packages: six, funcsigs, pbr, mock
Successfully installed funcsigs-1.0. mock-2.0. pbr-3.1. six-1.11.
04-26 23:15