天天看點

IPython Notebook安裝及使用

IPython Notebook安裝及使用

在做吳恩達deeplearning作業的時候,發現需要用到ipython,在使用的過程中遇到以下錯誤:

*****@Mac:~$ ipython
Traceback (most recent call last):
  File "/usr/local/bin/ipython", line , in <module>
    load_entry_point('ipython==', 'console_scripts', 'ipython')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line , 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 , in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line , in load
    return self.resolve()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line , in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=)
  File "/Library/Python/2.7/site-packages/ipython-5.3.0-py2.7.egg/IPython/__init__.py", line , 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 , 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 , 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 , in <module>
    from pathlib2 import Path
  File "build/bdist.macosx-10.13-intel/egg/pathlib2.py", line , in <module>
  File "build/bdist.macosx-10.13-intel/egg/scandir.py", line , in <module>
  File "build/bdist.macosx-10.13-intel/egg/_scandir.py", line , in <module>
  File "build/bdist.macosx-10.13-intel/egg/_scandir.py", line , in __bootstrap__
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line , in resource_filename
    self, resource_name
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line , 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 , in _extract_resource
    manager.extraction_error()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line , 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 ] Permission denied: '/Users/***/.python-eggs/scandir--py2-macosx--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  (default, Jul  , ::) 
Type "copyright", "credits" or "license" for more information.

IPython  -- 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//site-packages/jupyter--py2.egg
Collecting notebook (from jupyter)
  Downloading notebook--py2.py3-none-any.whl (MB)
    % |████████████████████████████████| MB kB/s 
Collecting qtconsole (from jupyter)
  Downloading qtconsole--py2.py3-none-any.whl (kB)
    % |████████████████████████████████| kB MB/s 
Collecting jupyter-console (from jupyter)
  Downloading jupyter_console--py2.py3-none-any.whl
Collecting nbconvert (from jupyter)
  Downloading nbconvert--py2.py3-none-any.whl (kB)
    % |████████████████████████████████| kB MB/s 
Requirement already satisfied: ipykernel in /Library/Python//site-packages (from jupyter)
Requirement already satisfied: ipywidgets in /Library/Python//site-packages/ipywidgets--py2.egg (from jupyter)
Requirement already satisfied: jupyter-core>= in /Library/Python//site-packages (from notebook->jupyter)
Requirement already satisfied: traitlets>= in /Library/Python//site-packages/traitlets--py2.egg (from notebook->jupyter)
Requirement already satisfied: ipython-genutils in /Library/Python//site-packages/ipython_genutils--py2.egg (from notebook->jupyter)
Collecting terminado>= (from notebook->jupyter)
  Downloading terminado--py2.py3-none-any.whl
Collecting jinja2 (from notebook->jupyter)
  Downloading Jinja2--py2.py3-none-any.whl (kB)
    % |████████████████████████████████| kB MB/s 
Collecting nbformat (from notebook->jupyter)
  Downloading nbformat--py2.py3-none-any.whl (kB)
    % |████████████████████████████████| kB MB/s 
Collecting Send2Trash (from notebook->jupyter)
  Downloading Send2Trash-.tar.gz
Requirement already satisfied: tornado>= in /Library/Python//site-packages/tornado-a1-py2-macosx--intel.egg (from notebook->jupyter)
Requirement already satisfied: jupyter-client>= in /Library/Python//site-packages (from notebook->jupyter)
Requirement already satisfied: pygments in /Library/Python//site-packages/Pygments--py2.egg (from qtconsole->jupyter)
Requirement already satisfied: ipython in /Library/Python//site-packages/ipython--py2.egg (from jupyter-console->jupyter)
Requirement already satisfied: prompt-toolkit<,>= in /Library/Python//site-packages/prompt_toolkit--py2.egg (from jupyter-console->jupyter)
Collecting mistune>= (from nbconvert->jupyter)
  Downloading mistune--py2.py3-none-any.whl
Collecting bleach (from nbconvert->jupyter)
  Downloading bleach--py2.py3-none-any.whl
Collecting testpath (from nbconvert->jupyter)
  Downloading testpath--py2.py3-none-any.whl (kB)
    % |████████████████████████████████| kB MB/s 
Collecting pandocfilters>= (from nbconvert->jupyter)
  Downloading pandocfilters-.tar.gz
Collecting entrypoints>= (from nbconvert->jupyter)
  Downloading entrypoints--py2.py3-none-any.whl
Collecting widgetsnbextension~= (from ipywidgets->jupyter)
  Downloading widgetsnbextension--py2.py3-none-any.whl (MB)
    % |████████████████████████████████| MB kB/s 
Requirement already satisfied: six in ./Library/Python//lib/python/site-packages (from traitlets>=->notebook->jupyter)
Requirement already satisfied: decorator in /Library/Python//site-packages/decorator--py2.egg (from traitlets>=->notebook->jupyter)
Requirement already satisfied: enum34 in /Library/Python//site-packages/enum34--py2.egg (from traitlets>=->notebook->jupyter)
Requirement already satisfied: ptyprocess; os_name != "nt" in /Library/Python//site-packages/ptyprocess--py2.egg (from terminado>=->notebook->jupyter)
Collecting MarkupSafe>= (from jinja2->notebook->jupyter)
  Downloading MarkupSafe-.tar.gz
Collecting jsonschema!=,>= (from nbformat->notebook->jupyter)
  Downloading jsonschema--py2.py3-none-any.whl
Requirement already satisfied: futures in /Library/Python//site-packages/futures--py2.egg (from tornado>=->notebook->jupyter)
Requirement already satisfied: singledispatch in /Library/Python//site-packages/singledispatch--py2.egg (from tornado>=->notebook->jupyter)
Requirement already satisfied: backports_abc>= in /Library/Python//site-packages/backports_abc--py2.egg (from tornado>=->notebook->jupyter)
Requirement already satisfied: pyzmq>= in /Library/Python//site-packages (from jupyter-client>=->notebook->jupyter)
Requirement already satisfied: python-dateutil>= in /Library/Python//site-packages/python_dateutil--py2.egg (from jupyter-client>=->notebook->jupyter)
Requirement already satisfied: setuptools>= in /System/Library/Frameworks/Python.framework/Versions//Extras/lib/python (from ipython->jupyter-console->jupyter)
Requirement already satisfied: pickleshare in /Library/Python//site-packages/pickleshare--py2.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: simplegeneric> in /Library/Python//site-packages/simplegeneric--py2.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: backports.shutil_get_terminal_size in /Library/Python//site-packages/backports.shutil_get_terminal_size--py2.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: pathlib2 in /Library/Python//site-packages/pathlib2--py2.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: pexpect in /Library/Python//site-packages/pexpect--py2.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: appnope in /Library/Python//site-packages/appnope--py2.egg (from ipython->jupyter-console->jupyter)
Requirement already satisfied: wcwidth in /Library/Python//site-packages/wcwidth--py2.egg (from prompt-toolkit<,>=->jupyter-console->jupyter)
Collecting html5lib!=b1,!=b2,!=b3,!=b4,!=b5,!=b6,!=b7,!=b8,>=pre (from bleach->nbconvert->jupyter)
  Downloading html5lib--py2.py3-none-any.whl (kB)
    % |████████████████████████████████| kB MB/s 
Requirement already satisfied: configparser>=; python_version == "2.7" in /Library/Python//site-packages (from entrypoints>=->nbconvert->jupyter)
Collecting functools32; python_version == "2.7" (from jsonschema!=,>=->nbformat->notebook->jupyter)
  Downloading functools32--zip
Requirement already satisfied: scandir in /Library/Python//site-packages/scandir--py2-macosx--intel.egg (from pathlib2->ipython->jupyter-console->jupyter)
Collecting webencodings (from html5lib!=b1,!=b2,!=b3,!=b4,!=b5,!=b6,!=b7,!=b8,>=pre->bleach->nbconvert->jupyter)
  Downloading webencodings--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 , 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 , 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 , in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/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-9.0.1-py2.7.egg/pip/req/req_install.py", line , 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 , 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 , in clobber
    ensure_dir(destdir)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line , in ensure_dir
    os.makedirs(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line , in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line , in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line , in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line , in makedirs
    mkdir(name, mode)
OSError: [Errno ] 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/,通路使用者目錄。