版本信息
系统版本
- ubuntu 18.04 64位
python版本
- python 系统自带2.7
- 自己装了一个python 3.6.9 64位系统
步骤
创建一个虚拟机
-
我打算在python3 安装jupyter 先安装一个pipenv
-
首先
pip3 install pipenv
安装虚拟管理包 -
然后在找一个合适目录,我的目录是jiao
-
然后输入
pipenv --python3.6
自定3.6版本创建一个虚拟环境 -
pipenv shell
进入虚拟环境 -
显示如图
-
里面是一个干净的python环境
-
sudo pipenv install jupyter
使用sudo执行命令 避免pip安装时权限问题 -
如果 因为超时安装失败 打开pipfile 文件 把里面的 url 设置 成
"https://pypi.tuna.tsinghua.edu.cn/simple/"
-
在安装 安装完成
-
安装完成
配置
- 在当前目录
touch conf.py
创建配置文件 - 输入python 进入命令行
- 输入
from notebook.auth import passwd
- 在输入
passwd()
- 根据提示 输入两次密码 之后生成一个秘钥 这个记住 会用到
c.NotebookApp.ip = '*' #所有绑定服务器的IP都能访问,若想只在特定ip访问,输入ip地址即可
c.NotebookApp.port = 8888 #将端口设置为自己喜欢的吧,默认是8888
c.NotebookApp.open_browser = False #我们并不想在服务器上直接打开Jupyter Notebook,所以设置成False
c.NotebookApp.notebook_dir = '/root/jupyter_projects' #这里是设置Jupyter的根目录,若不设置将默认root的根目录,不安全
c.NotebookApp.allow_root = True # 为了安全,Jupyter默认不允许以root权限启动jupyter
c.NotebookApp.password=u'秘钥'
eixt()
退出python环境- 运行
jupyter notebook --config conf.py
后台运行
sudo nohup jupyter notebook --config “绝对路径conf.py” >/dev/null 2>&1 &
nohup jupyter notebook >/dev/null 2>&1 &
查看进程
ps -ef | grep 'jupyter notebook'
ps -aux | grep jupyter
杀掉进程
- kill -9 21983
自动补全
ipython 无法自动补全
一般是 ipython 的版本 与 jedi版本问题 我的是指定一个jedi版本就好了 也可以降级ipython试试
在ipython里面 import 库 按tab 有补全就好了
- pip install jedi==0.17.2
jupyter 补全插件
安装nbextensions
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
安装 nbextensions_configurator
pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
重启jupyter
点击“Nbextensions”->取消“disable configuration for nbextensions without explicit compatibility (they may break your notebook environment, but can be useful to show for nbextension development)”->选择“Hinterland” 和Table of Contents(2)
反向代理
cd /etc/nginx/sites-available
- 新建一个 jupyter·_config文件
- 在里面设置
server {
listen 80;
server_name www.abc.com; #将localhost修改为您证书绑定的域名,例如:www.example.com。
location / {
proxy_pass http://localhost:8888/;
proxy_redirect default;
proxy_set_header host "127.0.0.1:8888";
proxy_set_header origin "http://127.0.0.1:8888";
proxy_set_header X-Real-IP "127.0.0.1";
# WebSocket proxying
proxy_http_version 1.1; # 这句一定要有 要不然 代理之后 报错kernel error
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
cd /etc/nginx/sites-enabled
ln -s ../sites-available/jupyter_config
- 重启 nginx
cd /usr/sbin
./nginx -s reload
问题
- 端口设置6666 和8000 连接不上 不知道为什么
- 设置https之后 报错 kernel error not found 也许是这个是我这个服务器的第二个网站有关???