原文:在centos7上搭建jupyter lab服务器

全新的阿里云ECS服务器上安装jupyter服务!

安装jupytrt lab

对于使用wget命令下载文件慢的情况,可以先在本地下完,然后上传至服务器!

  • 安装setuptools
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
  • 安装pip
wget https://files.pythonhosted.org/packages/ae/e8/2340d46ecadb1692a1e455f13f75e596d4eab3d11a57446f08259dee8f02/pip-10.0.1.tar.gz
tar -xzvf pip-10.0.1.tar.gz
cd pip-10.0.1
python setup.py install
cd ~
  • 安装gcc
yum install gcc
  • 安装python-devel
yum install python-devel  
  • 安装jupyterlab
pip install jupyterlab

配置jupyter

解决python2.7编码问题

错误提示:

【异常】 'ascii' codec can't decode byte 0xe8 in position 2: ordinal not in range(128)

这是因为python采用的是ascii编码,而python在进行编码方式之间转换时,会将unicode作为“中间编码”。但是unicode最大只有128长,因此会出现上面错误!

解决方案
/usr/lib/python2.7/site-packages目录下,新建sitecustomize.py文件,添加如下内容:

import sys
sys.setdefaultencoding('utf-8')

常规配置

  • 生成配置文件
jupyter notebook --generate-config
  • 创建一个密码
# ipyhon进入命令行执行python
ipython
from notebook.auth import passwd
passwd()
Enter password: 123456
Verify password: 123456
'sha1:e00ee9ab9a42:22e8c0dc771612348eeee698cde8ec77fba42e7f'
exit()
  • 编辑上面生成的配置文件
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha1:e00ee9ab9a42:22e8c0dc771612348eeee698cde8ec77fba42e7f'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888
c.NotebookApp.notebook_dir = u'/jupyter'

开放端口

关闭防火墙(不推荐)

systemctl stop firewalld
systemctl status firewalld

开放所配置的端口

firewall-cmd --zone=public --add-port=8080/tcp --permanent
ffirewall-cmd --reload

安装python3和jupyter的python3解释器

yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
cd ~
pip3 install --upgrade pip
python3 -m pip install ipykernel
python3 -m ipykernel install --user

安装R和jupyter的R解释器(选)

yum -y install epel-release
yum -y install R 
yum -y install curl 
yum -y install libcurl libcurl-devel 
yum -y install libxml2 libxml2-devel 
R
install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec()

其中install.packages命令执行时间较长,请耐心等待!

启动

jupyter lab --allow-root 

出错请使用下面命令行启动

LANG=zn jupyter lab --allow-root

后台运行

LANG=zn jupyter lab --allow-root >out.file 2>&1 &

Last modification:April 16th, 2020 at 01:27 pm