为 Python 2.7 安装 Jupyter Notebook

为 Python 2.7 安装 Jupyter Notebook

如何在 Ubuntu 14.04 中安装 Jupyter for Python 2.7?

我试过:

sudo add-apt-repository ppa:jolicloud-team/ppa
sudo apt-get update

更新的输出:

Ign file:  InRelease
Get:1 file:  Release.gpg [181 B]
Get:2 file:  Release [196 B]                                                   
Ign file:  Translation-en_US                                                   
Ign file:  Translation-en                                                      
Hit http://storage.googleapis.com stable InRelease         
Ign http://us.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 5,905 kB in 6s (915 kB/s)                                              
W: Failed to fetch http://ppa.launchpad.net/jolicloud-team/ppa/ubuntu/dists/trusty/main/binary-amd64/Packages  404  Not Found
W: Failed to fetch http://ppa.launchpad.net/jolicloud-team/ppa/ubuntu/dists/trusty/main/binary-i386/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.

进而:

sudo apt-get install jupiter

输出:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package jupiter

更新:

mona@pascal:~/computer_vision/imgur$ sudo python -m pip install --upgrade --force-reinstall pip
The directory '/home/mona/.cache/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 '/home/mona/.cache/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.
Collecting pip
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 721kB/s 
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-9.0.1
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
mona@pascal:~/computer_vision/imgur$ sudo -H pip install jupyter
Collecting jupyter
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading jupyter-1.0.0-py2.py3-none-any.whl
Collecting ipywidgets (from jupyter)
  Downloading ipywidgets-5.2.2-py2.py3-none-any.whl (43kB)
    100% |████████████████████████████████| 51kB 1.1MB/s 
Collecting qtconsole (from jupyter)
  Downloading qtconsole-4.2.1-py2.py3-none-any.whl (104kB)
    100% |████████████████████████████████| 112kB 2.1MB/s 
Collecting nbconvert (from jupyter)
  Downloading nbconvert-4.2.0-py2.py3-none-any.whl (319kB)
    100% |████████████████████████████████| 327kB 1.6MB/s 
Collecting notebook (from jupyter)
  Downloading notebook-4.2.3-py2.py3-none-any.whl (6.7MB)
    100% |████████████████████████████████| 6.7MB 154kB/s 
Collecting jupyter-console (from jupyter)
  Downloading jupyter_console-5.0.0-py2.py3-none-any.whl
Collecting ipykernel (from jupyter)
  Downloading ipykernel-4.5.0-py2.py3-none-any.whl (97kB)
    100% |████████████████████████████████| 102kB 5.2MB/s 
Collecting widgetsnbextension>=1.2.6 (from ipywidgets->jupyter)
  Downloading widgetsnbextension-1.2.6-py2.py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 674kB/s 
Collecting ipython>=4.0.0 (from ipywidgets->jupyter)
  Downloading ipython-5.1.0-py2-none-any.whl (747kB)
    100% |████████████████████████████████| 747kB 1.2MB/s 
Collecting traitlets>=4.2.1 (from ipywidgets->jupyter)
  Downloading traitlets-4.3.1-py2.py3-none-any.whl (74kB)
    100% |████████████████████████████████| 81kB 5.2MB/s 
Collecting pygments (from qtconsole->jupyter)
  Downloading Pygments-2.1.3-py2.py3-none-any.whl (755kB)
    100% |████████████████████████████████| 757kB 1.2MB/s 
Collecting jupyter-client>=4.1 (from qtconsole->jupyter)
  Downloading jupyter_client-4.4.0-py2.py3-none-any.whl (76kB)
    100% |████████████████████████████████| 81kB 5.0MB/s 
Collecting jupyter-core (from qtconsole->jupyter)
  Downloading jupyter_core-4.2.0-py2.py3-none-any.whl (76kB)
    100% |████████████████████████████████| 81kB 5.4MB/s 
Collecting entrypoints (from nbconvert->jupyter)
  Downloading entrypoints-0.2.2-py2.py3-none-any.whl
Collecting nbformat (from nbconvert->jupyter)
  Downloading nbformat-4.1.0-py2.py3-none-any.whl (140kB)
    100% |████████████████████████████████| 143kB 4.0MB/s 
Requirement already satisfied: jinja2 in /usr/lib/python2.7/dist-packages (from nbconvert->jupyter)
Collecting mistune!=0.6 (from nbconvert->jupyter)
  Downloading mistune-0.7.3-py2.py3-none-any.whl
Collecting terminado>=0.3.3; sys_platform != "win32" (from notebook->jupyter)
  Downloading terminado-0.6.tar.gz
Collecting tornado>=4 (from notebook->jupyter)
  Downloading tornado-4.4.2.tar.gz (460kB)
    100% |████████████████████████████████| 460kB 1.9MB/s 
Collecting ipython-genutils (from notebook->jupyter)
  Downloading ipython_genutils-0.1.0-py2.py3-none-any.whl
Collecting prompt-toolkit<2.0.0,>=1.0.0 (from jupyter-console->jupyter)
  Downloading prompt_toolkit-1.0.9-py2-none-any.whl (241kB)
    100% |████████████████████████████████| 245kB 2.7MB/s 
Requirement already satisfied: decorator in /usr/local/lib/python2.7/dist-packages (from ipython>=4.0.0->ipywidgets->jupyter)
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python2.7/dist-packages (from ipython>=4.0.0->ipywidgets->jupyter)
Collecting pickleshare (from ipython>=4.0.0->ipywidgets->jupyter)
  Downloading pickleshare-0.7.4-py2.py3-none-any.whl
Collecting backports.shutil-get-terminal-size; python_version == "2.7" (from ipython>=4.0.0->ipywidgets->jupyter)
  Downloading backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/lib/python2.7/dist-packages (from ipython>=4.0.0->ipywidgets->jupyter)
Collecting pathlib2; python_version == "2.7" or python_version == "3.3" (from ipython>=4.0.0->ipywidgets->jupyter)
  Downloading pathlib2-2.1.0-py2.py3-none-any.whl
Requirement already satisfied: simplegeneric>0.8 in /usr/lib/python2.7/dist-packages (from ipython>=4.0.0->ipywidgets->jupyter)
Requirement already satisfied: six in /usr/local/lib/python2.7/dist-packages (from traitlets>=4.2.1->ipywidgets->jupyter)
Collecting enum34; python_version == "2.7" (from traitlets>=4.2.1->ipywidgets->jupyter)
  Downloading enum34-1.1.6-py2-none-any.whl
Requirement already satisfied: pyzmq>=13 in /usr/lib/python2.7/dist-packages (from jupyter-client>=4.1->qtconsole->jupyter)
Collecting configparser>=3.5; python_version == "2.7" (from entrypoints->nbconvert->jupyter)
  Downloading configparser-3.5.0.tar.gz
Collecting jsonschema!=2.5.0,>=2.0 (from nbformat->nbconvert->jupyter)
  Downloading jsonschema-2.5.1-py2.py3-none-any.whl
Requirement already satisfied: markupsafe in /usr/lib/python2.7/dist-packages (from jinja2->nbconvert->jupyter)
Collecting ptyprocess (from terminado>=0.3.3; sys_platform != "win32"->notebook->jupyter)
  Downloading ptyprocess-0.5.1-py2.py3-none-any.whl
Collecting backports.ssl_match_hostname (from tornado>=4->notebook->jupyter)
  Downloading backports.ssl_match_hostname-3.5.0.1.tar.gz
Collecting singledispatch (from tornado>=4->notebook->jupyter)
  Downloading singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting certifi (from tornado>=4->notebook->jupyter)
  Downloading certifi-2016.9.26-py2.py3-none-any.whl (377kB)
    100% |████████████████████████████████| 378kB 2.1MB/s 
Collecting backports_abc>=0.4 (from tornado>=4->notebook->jupyter)
  Downloading backports_abc-0.4-py2.py3-none-any.whl
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.0->jupyter-console->jupyter)
  Downloading wcwidth-0.1.7-py2.py3-none-any.whl
Collecting functools32; python_version == "2.7" (from jsonschema!=2.5.0,>=2.0->nbformat->nbconvert->jupyter)
  Downloading functools32-3.2.3-2.zip
Building wheels for collected packages: terminado, tornado, configparser, backports.ssl-match-hostname, functools32
  Running setup.py bdist_wheel for terminado ... done
  Stored in directory: /root/.cache/pip/wheels/3b/c2/ea/af635ffb63857a8c2ddd22da6a4b52f5b7ea3065db94ef5d7c
  Running setup.py bdist_wheel for tornado ... done
  Stored in directory: /root/.cache/pip/wheels/b3/db/47/46e05d1ee3ecfba252fcab42f0a156dab0df0cddf99fa0827c
  Running setup.py bdist_wheel for configparser ... done
  Stored in directory: /root/.cache/pip/wheels/1c/bd/b4/277af3f6c40645661b4cd1c21df26aca0f2e1e9714a1d4cda8
  Running setup.py bdist_wheel for backports.ssl-match-hostname ... done
  Stored in directory: /root/.cache/pip/wheels/5d/72/36/b2a31507b613967b728edc33378a5ff2ada0f62855b93c5ae1
  Running setup.py bdist_wheel for functools32 ... done
  Stored in directory: /root/.cache/pip/wheels/3c/d0/09/cd78d0ff4d6cfecfbd730782a7815a4571cd2cd4d2ed6e69d9
Successfully built terminado tornado configparser backports.ssl-match-hostname functools32
Installing collected packages: configparser, entrypoints, enum34, ipython-genutils, traitlets, functools32, jsonschema, jupyter-core, nbformat, pygments, mistune, nbconvert, ptyprocess, backports.ssl-match-hostname, singledispatch, certifi, backports-abc, tornado, terminado, jupyter-client, pathlib2, pickleshare, backports.shutil-get-terminal-size, wcwidth, prompt-toolkit, ipython, ipykernel, notebook, widgetsnbextension, ipywidgets, qtconsole, jupyter-console, jupyter
  Found existing installation: tornado 3.1.1
    DEPRECATION: Uninstalling a distutils installed project (tornado) 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 tornado-3.1.1:
      Successfully uninstalled tornado-3.1.1
  Found existing installation: ipython 1.2.1
    DEPRECATION: Uninstalling a distutils installed project (ipython) 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 ipython-1.2.1:
      Successfully uninstalled ipython-1.2.1
  Rolling back uninstall of ipython
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 377, in move_wheel_files
    clobber(source, dest, False, fixer=fixer, filter=filter)
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 20] Not a directory: '/usr/local/share/man/man1/ipython.1.gz'
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
mona@pascal:~/computer_vision/imgur$ jupyter notebook
jupyter: 'notebook' is not a Jupyter command
mona@pascal:~/computer_vision/imgur$ jupyter
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
               [--paths] [--json]
               [subcommand]
jupyter: error: one of the arguments --version subcommand --config-dir --data-dir --runtime-dir --paths is required
mona@pascal:~/computer_vision/imgur$ 

答案1

Ubuntu 22.04 及更高版本

sudo apt install epiphany jupyter-notebook

创建jupyter_notebook_config.py者:

jupyter notebook --generate-config # type y for yes at the prompt

然后~/.jupyter/jupyter_notebook_config.py在文本编辑器中打开编辑并更改:

# c.NotebookApp.browser = ''

到:

c.NotebookApp.browser = '/usr/bin/epiphany'

不要忘记删除#行首的 ,这样它就不再是注释了。如果您不喜欢 Web,可以使用其他 Web 浏览器,只要它不是 snap 包,并且您将路径从 更改/usr/bin/epiphany为 Web 浏览器的路径,您可以通过运行以下形式的命令找到该路径which my-web-browser

但它仍然不起作用,所以你必须再做一步。将~/.local/share/jupyter目录的所有权从用户。 代替用户在下面的命令中将其替换为您登录的用户名。

sudo chown -R user:user ~/.local/share/jupyter 

在 Ubuntu 20.04 及更高版本中安装 Jupyter Notebook

打开终端并输入:

sudo apt install jupyter-notebook jupyter  

在 Ubuntu 18.04→19.10 中安装 Jupyter Notebook

打开终端并输入:

sudo apt install python3-notebook jupyter jupyter-core python-ipykernel  

要启动笔记本服务器,请运行以下命令:

jupyter notebook

您应该会看到 Jupyter Notebook 在您的网络浏览器中打开。

在 Ubuntu 17.04 和 17.10 中安装 Jupyter Notebook

在 Ubuntu 17.04 及更高版本中,Jupyter Notebook 在默认的 Ubuntu 存储库中可用,可以使用 apt 快速轻松地安装。打开终端并输入:

sudo apt install jupyter-notebook jupyter-core python-ipykernel 

python-ipykernel 是运行 Jupyter Notebook 中的 Python 2.x 程序所必需的,否则它仅支持 Python 3.x。

要启动笔记本服务器,请运行以下命令:

jupyter notebook

您应该会看到 Jupyter Notebook 在您的网络浏览器中打开。

在 Ubuntu 14.04→16.10 中安装 Jupyter Notebook

Ubuntu 中默认的 Python 版本可以正常运行,但是 pip 需要更新到最新版本。

sudo apt-get update
sudo apt-get -y install python-pip python-dev
sudo -H pip install --upgrade pip
sudo apt-get -y install ipython ipython-notebook
pip install --user jupyter

如果您使用的是 Python 3.x,请运行以下命令:

sudo apt-get update
sudo apt-get -y install python3-pip python3-dev
sudo -H pip3 install --upgrade pip
sudo apt-get -y install ipython3 ipython3-notebook
pip3 install --user jupyter

要启动 Jupyter Notebook,请运行以下命令:

jupyter notebook  

如果你还安装了 python-matplotlib,则在当前 Notebook 中启用绘图的第一行代码是%matplotlib inline

通过添加 Python 2 的内核,可以在 Jupyter Notebook 中使用 Python 3。如果你在 Python 3 上运行 Jupyter,则可以像这样设置 Python 2 内核:

python2 -m pip install ipykernel
python2 -m ipykernel install --user  

答案2

注意:本解决方案使用 Miniconda V4.12.0 和 Ubuntu 22.04

这对我有用:

  1. 安装 Miniconda。

  2. 跑步:

    conda create -y -n py27 python=2.7
    
  3. 跑步:

    conda activate py27
    
  4. 跑步:

    conda install -c "conda-forge/label/gcc7" jupyter
    
  5. 现在您可以自由运行jupyter notebook或使用 VSCode 的扩展。只需确保将内核更改为您刚刚安装的内核即可。

相关内容