一、jupyter notebook指定python解释器
一般情况下,jupyter所使用的解释器就是anaconda自带的解释器,而我们习惯使用的是虚拟环境的解释器。这里以指定虚拟环境的解释器为例
conda activate emotiona_analysis # 切换到虚拟环境emotiona_analysis pip install ipykernel # 在虚拟环境中安装 ipykernel 包python -m ipykernel install --name emotiona_analysis # 向 jupyter 中添加虚拟环境
完成以上步骤后重启jupyter即可
二、Python项目如何生成依赖库文件“requriements.txt”
pip install pipreqs #安装 pipreqs
# cd 到项目路径下,执行以下命令
# 如果已经存在requirements.txt,需要加上 --force 覆盖之
# 如果提示“UnicodeDecodeError: 'gbk' codec can't decode ”的错误,需要指定字符集 --encoding=utf8
# 如果有想要忽略的目录,可以使用 --ignore <dirs> ...忽略额外的目录
pipreqs ./ --encoding=utf8 --force # 生成requirements文件
pip install -r requirements.txt #使用 requirements.txt 安装依赖的方式
三、jupyter报错IProgress not found. Please update jupyter and ipywidgets
问题:
官方文档说的很清楚:如果你的jupyter和你运行代码的kernel不是一个环境的话,按底下这么做就行。
#第一步,在base环境运行:conda install -c conda-forge widgetsnbextension
#第二步,进入你的虚拟环境并运行(py36是你虚拟环境的名字,自行替换):source activate py36
conda install -c conda-forge ipywidgets
#或者直接像官方文档图那样的直接安装到指定名字的环境里面也行。