Using a virtualenv in an IPython notebook
You can use a virtualenv for your IPython notebook. Follow the following steps:
Install the ipython kernel module into your virtualenv
也可使用conda env
workon my-virtualenv-name # activate your virtualenv, if you haven't already
# or activate env-name
pip install ipykernel
Now run the kernel “self-install” script:
python -m ipykernel install --user --name={my-virtualenv-name}
Replacing the –name parameter as appropriate.
You should now be able to see your kernel in the IPython notebook menu: Kernel -> Change kernel and be able so switch to it (you may need to refresh the page before it appears in the list). IPython will remember which kernel to use for that notebook from then on.
jupyter 启动报错 Permission denied: ‘/run/user/0/jupyter’
解决办法:
将/root/.jupyter 目录复制到 /home/long/.jupyter目录下(long是我的用户名),修改权限为755
chown long:long .jupyter
chmod 755 -R .jupyter
然后在/etc/profile 中添加下面这行:
export XDG_RUNTIME_DIR='/home/long/.jupyter'
执行source /etc/profile, 使修改生效。
可以参考:python +jupyter (python3.5) 实现词云(png)
centos7安装jupyter并配置多个Python版本切换
做完上面的工作之后,我们就可以在Jupyter NoteBook中使用下面的方法使用该env环境了.