windows10安装jupyter notebook

windows10:

在安装python3.8.5时,后面两项别选择(一般也用不到),因其安装需要连网,可能会受限。(但今天在移动宽带下,选了后两项也很快安装好了2020.7.27)

python -m pip install --upgrade pip
python -m pip install --upgrade pip setuptools wheel

 

卸载pip uninstall 包名
安装pip install 包文件名(whl文件)

安装pip install jupyter notebook

https://pypi.org/project/notebook/#modal-close

pip install notebook

如出现错误:一片暗红色字,内容如:

pip._vendor.ur11ih3 exceptions ReadT imeout Error: HTT PSConnect ionPoo 1Chost='f ile s pythonhosted.org' port=443)8 Read t imed out

解决办法:

pip --default-timeout=100 install 库名称 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

pip --default-timeout=100 install jupyter notebook -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 

可替换源:

清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/ 豆瓣:http://pypi.douban.com/simple/

查看jupyter notebook版本(https://packaging.python.org/tutorials/installing-packages/)

If you’re using an enhanced shell like IPython or the Jupyter notebook, you can run system commands like those in this tutorial by prefacing them with a ! character:注意,本机安装python3.8.5,不用!,直接用sys.version.

In [1]: import sys
        sys.version
Out[1]:
        '3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]'

It’s recommended to write {sys.executable} rather than plain python in order to ensure that commands are run in the Python installation matching the currently running notebook (which may not be the same Python installation that the python command refers to).

启动 notebook

在终端环境下输入 jupyter notebook

我常用的方式是:

1.在f盘里建一个文件夹--比如python_learn,进入这个文件夹,建立一个批处理文件,jupyter nootbook.bat,内容为:jupyter notebook

2.在桌面建一个快捷方式(右击批处理文件,发送到桌面。)

3.启动时,只需双击桌面快捷图标。

批处理文件所在的文件夹,将自动成为notebook的根目录:

windows10安装jupyter notebook_第1张图片

windows10安装jupyter notebook_第2张图片

帮助,快捷键:

单元格 蓝色 状态(在单元格左端单击,此时为行命令模式),按 "h" 

单元格为绿色时,是代码编辑器模式。

两种模式下的快捷键功能有不同。

jupyter notebook源自于一个IPython 项目,所以其保存为 JSON 文件,文件扩展名为.ipynb,保存位置,服务器

Magic关键字是 IPython 的一些高级用法,可以运行特殊的命令,然后控制 notebook。

Magic 命令的前面

带有一个%,代表行 Magic 命令

两个百分号 %%,代表单元格 Magic 命令

行 Magic 命令仅应用于编写 Magic 命令时所在的行,而单元格 Magic 命令应用于整个单元格。

如果要测算整个单元格的运行时间,请使用 %%timeit,如下所示:

windows10安装jupyter notebook_第3张图片

疑障:运行代码,但单元格左边有*,这有可能是运算时间比较常,还没有输出,未必就是故障。

windows10安装jupyter notebook_第4张图片

import random
%%timeit
prize=0
for ii in range(100):
    roll=random.randint(1,6)
    if roll%2==0:
        prize+=roll
    else:
        prize -=1        

如果要在 notebook 中嵌入可视化内容,可以说使用 %matplotlib inline,如下所示:

%matplotlib inline

%config InlineBackend.figure_format='retina'  #高分辨率

import matplotlib.pyplt as plt

import numpy as np

关于ipython的%命令,参阅https://ipython.readthedocs.io/en/stable/interactive/magics.html

安装matplotlib

pip --default-timeout=100 install matplotlib -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

pip --default-timeout=100 install 库名称 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

%matplotlib inline

%config InlineBackend.figure_format='retina'

import matplotlib.pyplot as plt

import numpy as np

x=np.linspace(0,1,300)
for w in range(2,6,2):
    plt.plot(x,np.sin(np.pi*x)*np.sin(2*w*np.pi*x))

windows10安装jupyter notebook_第5张图片


jupyter notebook的自定义启动
https://www.cnblogs.com/zlslch/p/6984403.html


自定义启动

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>cd /d D:\

D:\>cd D:\SoftWare\Python\Python36\Scripts

D:\SoftWare\Python\Python36\Scripts>jupyter notebook --generate-config
Writing default config to: C:\Users\Administrator\.jupyter\jupyter_notebook_conf
ig.py

D:\SoftWare\Python\Python36\Scripts>

修改jupyter_notebook_config.py配置文件
  打开这个配置文件,找到“c.NotebookApp.notebook_dir=……”,把路径改成自己的工作目录。

比如,这里要变更为

## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = 'D:\Code\jupyter-notebook'

,当然,文件夹 jupyter-notebook 需要自己提前创建好。 


 

 

你可能感兴趣的:(日益精进,python,python)