ubun更改默认python,配置jupyter

该博客指导如何查看及切换Python版本,安装和更新pip,安装并配置Jupyter Notebook,包括设置密码、修改配置文件以指定IP和端口,并解决权限问题。还介绍了如何启用代码补全功能和将虚拟环境添加到Jupyter。最后,提供了处理常见错误的方法。
摘要由CSDN通过智能技术生成

查看系统所有python

ls /usr/bin/python*

查看默认python

python --version

只修改当前用户

vim ~/.bashrc

#修改默认python版本
alias python='/usr/bin/python3.6'

系统级修改

#删除默认软链接
sudo rm /usr/bin/python

#创建新软链接指向需要的版本
sudo ln -s /usr/bin/python3.6 /usr/bin/python

安装pip

#安装
sudo apt install python3-pip

#更新
pip3 install --upgrade pip

若报错TypeError: expected str, bytes or os.PathLike object, not int

curl https://bootstrap.pypa.io/get-pip.py | python3 -

#若报错,则将链接更换为提示链接

安装jupyter

#安装
pip3 install jupyter

#生成配置文件
jupyter notebook --generate-config --allow-root

#设置密码
jupyter notebook password

修改配置文件

vim ~/.jupyter/jupyter_notebook_config.py

#ip(取消注释,指定ip)
c.NotebookApp.ip = '192.168.10.xxx'

#端口(取消注释,指定端口)
c.NotebookApp.port = 8888

#密码(若需要则取消注释,改为True)
c.NotebookApp.password_required = True

添加代码补全(若需要)

# 安装nbextensions
pip3 install jupyter_contrib_nbextensions
sudo jupyter contrib nbextension install --user

# 安装nbextensions_configurator
pip3 install jupyter_nbextensions_configurator
sudo jupyter nbextensions_configurator enable --user

启动jupyter,后台运行

nohup jupyter notebook &

浏览器登陆,点开Nbextensions,勾选Hinterland

若报错PermissionError: [Errno 13] Permission denied: '/opt/anaconda3/share/jupyter/nbconvert/templates/html/conf.json'

#删除
sudo rm  -rvf /usr/share/jupyter
rm -rvf  ~/.local/share/jupyter

#授予权限
chmod -R 777 /usr/local/share/jupyter/nbconvert/templates/html

#重启jupyter

将虚拟环境加入jupyter

python ipykernel install --user --name venvname

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值