win10 下通过Anaconda 安装keras,pytorch,jupyter notebook (CPU版)

环境准备

Anaconda3-5.3.0-Windows-x86_64 (PYTHON 3.7)

安装

分别创建3个环境

conda create -n jupyter python=3.6 作为jupyter notebook启动的默认环境,安装scikitlearn等机器学习库

conda create -n pytorch python=3.7 pytorch 使用,安装fastai

conda create -n keras python=3.6 keras和tensorflow

keras

1
2
3
4
5
6
7
activate keras
#使用cpu版本可以直接使用conda安装,版本1.9.0,最近版1.11.0
conda install keras
#安装ipykernel
conda install ipykernel
#写入环境
python -m ipykernel install --user --name keras --display-name "keras with tensorflow"

pytorch

1
2
3
4
5
6
7
8
activate pytorch
#pytorch官网支持conda直接安装
conda install pytorch-cpu -c pytorch
pip3 install torchvision
#安装ipykernel
conda install ipykernel
#写入环境
python -m ipykernel install --user --name pytorch --display-name "pytorch with fastai"

打开Anaconda Navigator 在jupyter中安装jupyter book,然后打开可以看到两个新建的环境,启动即可

删除环境

1
conda env remove -n [环境名]

配置jupyter book

1
2
3
activate jupyter
jupyter notebook --generate-config
## 这里会显示创建jupyter_notebook_config.py的具体位置

打开文件,修改

1
2
c.NotebookApp.notebook_dir = '' #默认目录位置
c.NotebookApp.iopub_data_rate_limit = 100000000 # 这个改大一些否则有可能报错

问题

启动python提示编码错误

1
2
3
4
5
6
7
8
9
10
11
Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 11:48:23) [MSC v.1900 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\tant\Anaconda3\envs\keras\lib\site.py", line 418, in register_readline
readline.read_history_file(history)
File "C:\Users\tant\Anaconda3\envs\keras\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "C:\Users\tant\Anaconda3\envs\keras\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 0xae in position 372: illegal multibyte sequence

找到 用户文件夹下的 .python_history 删除