查看系统所有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

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐