IPython Notebook安装及使用

在做吴恩达deeplearning作业的时候,发现需要用到ipython,在使用的过程中遇到以下错误:

*****@Mac:~$ ipython
Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 9, in <module>
    load_entry_point('ipython==5.3.0', 'console_scripts', 'ipython')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 565, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2697, in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2370, in load
    return self.resolve()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2376, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Library/Python/2.7/site-packages/ipython-5.3.0-py2.7.egg/IPython/__init__.py", line 49, in <module>
    from .terminal.embed import embed
  File "/Library/Python/2.7/site-packages/ipython-5.3.0-py2.7.egg/IPython/terminal/embed.py", line 15, in <module>
    from IPython.core import magic_arguments
  File "/Library/Python/2.7/site-packages/ipython-5.3.0-py2.7.egg/IPython/core/magic_arguments.py", line 60, in <module>
    from IPython.utils.text import dedent
  File "/Library/Python/2.7/site-packages/ipython-5.3.0-py2.7.egg/IPython/utils/text.py", line 21, in <module>
    from pathlib2 import Path
  File "build/bdist.macosx-10.13-intel/egg/pathlib2.py", line 45, in <module>
  File "build/bdist.macosx-10.13-intel/egg/scandir.py", line 30, in <module>
  File "build/bdist.macosx-10.13-intel/egg/_scandir.py", line 7, in <module>
  File "build/bdist.macosx-10.13-intel/egg/_scandir.py", line 4, in __bootstrap__
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 1168, in resource_filename
    self, resource_name
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 1876, in get_resource_filename
    self._extract_resource(manager, self._eager_to_zip(name))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 1936, in _extract_resource
    manager.extraction_error()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 1214, in extraction_error
    raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 13] Permission denied: '/Users/***/.python-eggs/scandir-1.6-py2.7-macosx-10.13-intel.egg-tmp/tmpkTNwXG.$extract'

The Python egg cache directory is currently set to:

  /Users/*****/.python-eggs

Perhaps your account does not have write access to this directory?  You can change the cache directory by setting the PYTHON_EGG_CACHE environment variable to point to an accessible directory.

上面的这个问题,可以通过以下语句进行更正:

sudo chown -R *** /Users/***/.python-eggs/

再次在终端输入ipython就会显示正常的结果:

Python 2.7.10 (default, Jul 15 2017, 17:16:57) 
Type "copyright", "credits" or "license" for more information.

IPython 5.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

安装jupyter,在终端输入 sudo pip install jupyter,但是遇到以下问题:

The directory '/Users/***/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/***/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: jupyter in /Library/Python/2.7/site-packages/jupyter-1.0.0-py2.7.egg
Collecting notebook (from jupyter)
  Downloading notebook-5.4.0-py2.py3-none-any.whl (8.0MB)
    100% |████████████████████████████████| 8.0MB 187kB/s 
Collecting qtconsole (from jupyter)
  Downloading qtconsole-4.3.1-py2.py3-none-any.whl (108kB)
    100% |████████████████████████████████| 112kB 6.3MB/s 
Collecting jupyter-console (from jupyter)
  Downloading jupyter_console-5.2.0-py2.py3-none-any.whl
Collecting nbconvert (from jupyter)
  Downloading nbconvert-5.3.1-py2.py3-none-any.whl (387kB)
    100% |████████████████████████████████| 389kB 2.3MB/s 
Requirement already satisfied: ipykernel in /Library/Python/2.7/site-packages (from jupyter)
Requirement already satisfied: ipywidgets in /Library/Python/2.7/site-packages/ipywidgets-7.1.0-py2.7.egg (from jupyter)
Requirement already satisfied: jupyter-core>=4.4.0 in /Library/Python/2.7/site-packages (from notebook->jupyter)
Requirement already satisfied: traitlets>=4.2.1 in /Library/Python/2.7/site-packages/traitlets-4.3.2-py2.7.egg (from notebook->jupyter)
Requirement already satisfied: ipython-genutils in /Library/Python/2.7/site-packages/ipython_genutils-0.2.0-py2.7.egg (from notebook->jupyter)
Collecting terminado>=0.8.1 (from notebook->jupyter)
  Downloading terminado-0.8.1-py2.py3-none-any.whl
Collecting jinja2 (from notebook->jupyter)
  Downloading Jinja2-2.10-py2.py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 6.2MB/s 
Collecting nbformat (from notebook->jupyter)
  Downloading nbformat-4.4.0-py2.py3-none-any.whl (155kB)
    100% |████████████████████████████████| 163kB 5.3MB/s 
Collecting Send2Trash (from notebook->jupyter)
  Downloading Send2Trash-1.4.2.tar.gz
Requirement already satisfied: tornado>=4 in /Library/Python/2.7/site-packages/tornado-5.0a1-py2.7-macosx-10.13-intel.egg (from notebook->jupyter)
Requirement already satisfied: jupyter-client>=5.2.0 in /Library/Python/2.7/site-packages (from notebook->jupyter)
Requirement already satisfied: pygments in /Library/Python/2.7/site-packages/Pygments-2.2.0-py2.7.egg (from qtconsole->jupyter)
Requirement already satisfied: ipython in /Library/Python/2.7/site-packages/ipython-5.3.0-py2.7.egg (from jupyter-console->jupyter)
Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.0 in /Library/Python/2.7/site-packages/prompt_toolkit-1.0.15-py2.7.egg (from jupyter-console->jupyter)
Collecting mistune>=0.7.4 (from nbconvert->jupyter)
  Downloading mistune-0.8.3-py2.py3-none-any.whl
Collecting bleach (from nbconvert->jupyter)
  Downloading bleach-2.1.2-py2.py3-none-any.whl
Collecting testpath (from nbconvert->jupyter)
  Downloading testpath-0.3.1-py2.py3-none-any.whl (161kB)
    100% |████████████████████████████████| 163kB 4.5MB/s 
Collecting pandocfilters>=1.4.1 (from nbconvert->jupyter)
  Downloading pandocfilters-1.4.2.tar.gz
Collecting entrypoints>=0.2.2 (from nbconvert->jupyter)
  Downloading entrypoints-0.2.3-py2.py3-none-any.whl
Collecting widgetsnbextension~=3.1.0 (from ipywidgets->jupyter)
  Downloading widgetsnbextension-3.1.3-py2.py3-none-any.whl (2.2MB)
    100% |████████████████████████████████| 2.2MB 602kB/s 
Requirement already satisfied: six in ./Library/Python/2.7/lib/python/site-packages (from traitlets>=4.2.1->notebook->jupyter)
Requirement already satisfied: decorator in /Library/Python/2.7/site-packages/decorator-4.1.2-py2.7.egg (from traitlets>=4.2.1->notebook->jupyter)
Requirement already satisfied: enum34 in /Library/Python/2.7/site-packages/enum34-1.1.6-py2.7.egg (from traitlets>=4.2.1->notebook->jupyter)
Requirement already satisfied: ptyprocess; os_name != "nt" in /Library/Python/2.7/site-packages/ptyprocess-0.5.2-py2.7.egg (from terminado>=0.8.1->notebook->jupyter)
Collecting MarkupSafe>=0.23 (from jinja2->notebook->jupyter)
  Downloading MarkupSafe-1.0.tar.gz
Collecting jsonschema!=2.5.0,>=2.4 (from nbformat->notebook->jupyter)
  Downloading jsonschema-2.6.0-py2.py3-none-any.whl
Requirement already satisfied: futures in /Library/Python/2.7/site-packages/futures-3.2.0-py2.7.egg (from tornado>=4->notebook->jupyter)
Requirement already satisfied: singledispatch in /Library/Python/2.7/site-packages/singledispatch-3.4.0.3-py2.7.egg (from tornado>=4->notebook->jupyter)
Requirement already satisfied: backports_abc>=0.4 in /Library/Python/2.7/site-packages/backports_abc-0.5-py2.7.egg (from tornado>=4->notebook->jupyter)
Requirement already satisfied: pyzmq>=13 in /Library/Python/2.7/site-packages (from jupyter-client>=5.2.0->notebook->jupyter)
Requirement already satisfied: python-dateutil>=2.1 in /Library/Python/2.7/site-packages/python_dateutil-2.6.1-py2.7.egg (from jupyter-client>=5.2.0->notebook->jupyter)
Requirement already satisfied: setuptools>=18.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from ipython->jupyter-console->jupyter)
Requirement already satisfied: pickleshare in /Library/Python/2.7/site-packages/pickleshare-0.7.4-py2.7.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: simplegeneric>0.8 in /Library/Python/2.7/site-packages/simplegeneric-0.8.1-py2.7.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: backports.shutil_get_terminal_size in /Library/Python/2.7/site-packages/backports.shutil_get_terminal_size-1.0.0-py2.7.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: pathlib2 in /Library/Python/2.7/site-packages/pathlib2-2.3.0-py2.7.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: pexpect in /Library/Python/2.7/site-packages/pexpect-4.3.1-py2.7.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: appnope in /Library/Python/2.7/site-packages/appnope-0.1.0-py2.7.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: wcwidth in /Library/Python/2.7/site-packages/wcwidth-0.1.7-py2.7.egg (from prompt-toolkit<2.0.0,>=1.0.0->jupyter-console->jupyter)
Collecting html5lib!=1.0b1,!=1.0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999999pre (from bleach->nbconvert->jupyter)
  Downloading html5lib-1.0.1-py2.py3-none-any.whl (117kB)
    100% |████████████████████████████████| 122kB 5.9MB/s 
Requirement already satisfied: configparser>=3.5; python_version == "2.7" in /Library/Python/2.7/site-packages (from entrypoints>=0.2.2->nbconvert->jupyter)
Collecting functools32; python_version == "2.7" (from jsonschema!=2.5.0,>=2.4->nbformat->notebook->jupyter)
  Downloading functools32-3.2.3-2.zip
Requirement already satisfied: scandir in /Library/Python/2.7/site-packages/scandir-1.6-py2.7-macosx-10.13-intel.egg (from pathlib2->ipython->jupyter-console->jupyter)
Collecting webencodings (from html5lib!=1.0b1,!=1.0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999999pre->bleach->nbconvert->jupyter)
  Downloading webencodings-0.5.1-py2.py3-none-any.whl
Installing collected packages: terminado, MarkupSafe, jinja2, mistune, functools32, jsonschema, nbformat, webencodings, html5lib, bleach, testpath, pandocfilters, entrypoints, nbconvert, Send2Trash, notebook, qtconsole, jupyter-console, widgetsnbextension
  Running setup.py install for MarkupSafe ... done
  Running setup.py install for functools32 ... done
  Running setup.py install for pandocfilters ... done
  Running setup.py install for Send2Trash ... done
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 377, in move_wheel_files
    clobber(source, dest, False, fixer=fixer, filter=filter)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 1] Operation not permitted: '/System/Library/Frameworks/Python.framework/Versions/2.7/etc'

经过百度,需要upgrade pip,在终端输入:pip install –upgrade pip后,再次执行 sudo pip install jupyter即可成功。

然后在终端输入jupyter notebook 启动,会默认打开http://localhost:8888/,访问用户目录。

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐