Mac上的Ansible安装错误

时间:2016-08-09 12:01:05

标签: python macos ansible

在Mac上安装Ansible(10.11.6)我在这里http://docs.ansible.com/ansible/intro_installation.html进入“安装Python模块”部分并收到此错误:

sudo pip install paramiko PyYAML Jinja2 httplib2 six

... lots of downloading ...

Installing collected packages: pyasn1, pycparser, cffi, setuptools, idna, ipaddress, enum34, cryptography, paramiko, PyYAML, MarkupSafe, Jinja2, httplib2
Running setup.py install for pycparser ... done
Found existing installation: setuptools 1.1.6
Uninstalling setuptools-1.1.6:

Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 736, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 742, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move
    copytree(src, real_dst, symlinks=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 208, in copytree
    raise Error, errors
Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', "[Errno 1] Operation not permitted: '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', "[Errno 1] Operation not permitted: '/tmp/pip-QJiMr7-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'")]

知道问题是什么吗?

3 个答案:

答案 0 :(得分:0)

如果您不介意安装用户,请致电pip install --user ansible并享受 在El Capitan升级之后,Mac OS在安装全球软件包时遇到了一些麻烦。

答案 1 :(得分:0)

USX上存在版本冲突,安装版本为6。已安装的版本(OSX附带的版本)可以使用,但是pip不知道它会起作用。不要尝试用pip安装六个。当您安装Ansible时,请使用以下命令:

sudo -H pip install ansible --upgrade --ignore-installed six

这告诉pip忽略与6的冲突并假设已安装的版本可以正常工作。

答案 2 :(得分:0)

OSX最近进行了更改,以便您可能会遇到(迟早)驻留在系统上的python模块与您需要安装的内容之间的不兼容性。 Ansible是一个很好的例子,因为它的依赖关系不再适合已安装的东西。

干净的解决方案是使用虚拟环境: https://virtualenv.pypa.io/en/stable/userguide/#usage

很简单,您正在创建一个泡泡,可以在其中安装和运行您的python版本及其模块。它是这样的:

$ virtualenv myenv
New python executable in myenv/bin/python
Installing setuptools, pip...done.

$ ls -lah myenv
total 8
drwxr-xr-x   6 migueldavid  staff   204B 19 Aug 14:45 .
drwxr-xr-x+ 60 migueldavid  staff   2.0K 19 Aug 14:45 ..
lrwxr-xr-x   1 migueldavid  staff    63B 19 Aug 14:45 .Python -> /System/Library/Frameworks/Python.framework/Versions/2.7/Python
drwxr-xr-x  14 migueldavid  staff   476B 19 Aug 14:45 bin
drwxr-xr-x   3 migueldavid  staff   102B 19 Aug 14:45 include
drwxr-xr-x   3 migueldavid  staff   102B 19 Aug 14:45 lib

然后激活虚拟环境并安装所需的任何内容:

$ source myenv/bin/activate
(myenv)$ pip install ansible
Downloading/unpacking ansible
  Downloading ansible-2.1.1.0.tar.gz (1.9MB): 1.9MB downloaded
(...)

要摆脱这个"沙盒",您只需键入

即可
$ deactivate

我希望这会有所帮助。