Jupyter 安装在 Mac 上失败

Jupyter install fails on Mac

我正在尝试在我的 Mac(OS X El Capitan)上安装 Jupyter,但我收到一个错误响应:

sudo pip install -U jupyter

一开始 download/install 很好,但后来我 运行 变成了这个:

Installing collected packages: six, singledispatch, certifi, backports-abc, tornado, jupyter-core, pyzmq, jupyter-client, functools32, jsonschema, nbformat, pygments, mistune, MarkupSafe, jinja2, nbconvert, path.py, pickleshare, simplegeneric, setuptools, gnureadline, appnope, ptyprocess, pexpect, ipython, ipykernel, terminado, notebook, ipywidgets, jupyter-console, qtconsole, jupyter
  Found existing installation: six 1.4.1
    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.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 726, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 746, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/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 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-ByX5xW-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

我该怎么做才能解决这个问题?

不幸的是,El Capitan 附带的默认 OS X Python 包装错误相当严重(grrr,Apple)。他们不仅运送了一些已经安装的相当奇怪的第 3 方软件包,而且还运送了这些软件包的奇怪(旧)和测试版。此外,它们非常 system protected.

这使得默认的 python 不适合使用(如您所见)。在你的具体情况下,juypter 想安装最新版本的六个库,但系统安装的版本是一个奇怪的旧版本,不会让 pip 更新它(jupyter 需要更新版本)。

一般来说,为了减轻未来所有的麻烦,我建议获得 python 的不同分布,并将其放在您的路径中,使其成为您的新默认值。有几个选择;重要的是一次只使用一个(否则它们很容易混淆彼此,或混淆你)。

  1. Python.org - 来自 Python 开发者自己
  2. Homebrew - OS X 的 unixy 包管理器,它有一个正常运行的 python 包
  3. Anaconda Python - 一个科学的 python 发行版,已经有许多 'harder-to-install' 科学包和 'just working'(包括 jupyter)。

如果您不知道该选择什么,我建议您暂时使用 Anaconda。

Ivo 的答案是正确的 - 最好的解决方案是修复您的 python 安装。下面是一个使用 Homebrew 的例子(我强烈推荐):

安装自制软件:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew upgrade

安装Python:

brew install python

或Python 3:

brew install python3

Upgrade/install:

pip install --upgrade pip setuptools

安装 jupyter:

pip install jupyter

注意:您可能需要将 sudo -Hpip install

一起使用

或者你可以试试

sudo pip install -U jupyter --upgrade --ignore-installed six

此命令将为当前登录的用户安装 jupyter,不会忽略任何内容:

sudo pip install --user jupyter