python jupyter theme

 

python安装

python download

jupyter安装

pip install jupyter notebook
# 代码补全插件
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

启动

jupyter notebook
# open http://localhost:8888

jupyter-theme安装

github: jupyter-themes

# 安装jupyter主题
pip install jupyterthemes
# 加载可用主题列表 onedork | grade3 | oceans16 | chesterish | monokai | solarizedl | solarizedd
jt -l
# 选择主题, 应用 -T 显示toolbar -N 显示名称和logo
jt -t onedork -T -N

toolbar悬浮的问题

参考: Toolbar background not visible

修改文件<python-site-packages-path>/jupyterthemes/layout/notebook.less

找到div#maintoolbar, 然后注释掉position:absolute;

div#maintoolbar {
    /* position: absolute; */
    width: 90%;
    margin-left: -10%;
    padding-right: 8%;
    float: left;
    background: transparent !important;
}

anaconda安装

Anaconda Installers

Anaconda就是可以便捷获取包且对包能够进行管理,同时对环境可以统一管理的发行版本。Anaconda包含了conda、Python在内的超过180个科学包及其依赖项。

conda是包及其依赖项和环境的管理工具。

# 显示创建环境
conda info -e
# 复制环境
conda create --name <new_env_name> --clone <copied_env_name>
# 删除环境
conda remove --name <env_name> --all

# 激活环境
source activate <env_name>
# windows 激活环境
activate <env_name>
# 退出环境
source deactivate
# windows 退出环境
deactivate

# 查找包
conda search --full-name <package_full_name>
# 模糊查找
conda search <text>
# 显示所有包
conda list
# 在指定环境中安装包
conda install --name <env_name> <package_name>
# 在当前环境中安装包
conda install <package_name>
# 也可以通过pip安装
pip install <package_name>
# 卸载指定环境中的包
conda remove --name <env_name> <package_name>
# 卸载当前环境中的包
conda remove <package_name>
# 更新所有包
conda update --all
# 更新指定包
conda update <package_name>

python 启动报错

Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "C:/Users/Lenovo/AppData/Local/Programs/Python/Python39/lib/site.py", line 449, in register_readline
    readline.read_history_file(history)
  File "C:/Users/Lenovo/AppData/Local/Programs/Python/Python39/lib/site-packages/pyreadline/rlmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "C:/Users/Lenovo/AppData/Local/Programs/Python/Python39/lib/site-packages/pyreadline/lineeditor/history.py", line 82, in read_history_file
    for line in open(filename, 'r'):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xbd in position 15: illegal multibyte sequence

解决方法

由于默认.python_history历史命令写的是utf-8格式, 而读取的是使用的gbk格式, 导致的问题

  1. 删除.python_history文件, 之后还会出现
  2. 修改history.py文件
for line in open(filename, 'r', encoding='utf-8'):

参考