安装anaconda
- 清华镜像站下载anaconda.sh文件
- 安装anaconda
#打开终端,转到anaconda.sh所在目录下并使用如下语句安装
bash anaconda.sh
- 配置anaconda环境
#打开终端,输入
sudo gedit ~/.bashrc
#在文档最后一行加上
export PATH="/home/xy/anaconda3/bin:$PATH" #anaconda安装文件的bin目录路径
#终端下输入
source ~/.bashrc
安装配置jupyter-hub
- 安装jupyter-hub
conda install -c conda-forge jupyterhub
- 设置配置文件
终端下输入如下代码生成配置文件
jupyterhub --generate-config
修改配置文件,以下是我的配置文件(默认以ubuntu用户名和密码登录)
c.PAMAuthenticator.encoding = 'utf-8'
c.LocalAuthenticator.create_system_users = True
c.JupyterHub.ip = '10.112.10.122'
c.JupyterHub.port = 8000
c.JupyterHub.ssl_cert = '/home/wsy/software/anaconda3/jupyterhub/mycert.pem'
c.JupyterHub.ssl_key = '/home/wsy/software/anaconda3/jupyterhub/mykey.key'
c.JupyterHub.statsd_prefix = 'jupyterhub'
c.Authenticator.admin_users = {'wsy'}
c.Authenticator.delete_invalid_users = True
from jupyterhub.spawner import LocalProcessSpawner
class MySpawner(LocalProcessSpawner):
def _notebook_dir_default(self):
return '/home/' + self.user.name
c.JupyterHub.spawner_class = MySpawner
运行Jupyterhub
终端转到配置文件所在目录下,输入如下代码启动jupyterhub
jupyterhub
打开浏览器,输入网址https:\10.112.10.122:8080(你的配置文件中的ip和端口),输入ubuntu用户名和密码即可登录使用
注:jupyterhub中添加新的kernel与jupyter notebook中的操作步骤相同
#进入要添加到kernel的环境
conda activate tensorflowq #例如环境为tensorflowq
pip install ipykernel
python -m ipykernel install --user --name tensorflowq
#jupyter kernelspec remove kernelname #如不使用了,可使用该语句删除kernel