最近发现一个很不错的工具juypter,用完之后爱不释手,我很喜欢Jupyter,它可以把代码和自己的思路记录下载。整理一下就可以是一个笔记,但是由于电脑经常换,有必要在服务器上装一个(Python环境和模块已经装好了)
环境:centos7(Docker) 使用的python集成环境anaconda
1.生成配置文件
jupyter notebook --generate-config
2.打开ipython创建一个密码
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:*****************************************'
把密文记录下来
3.修改配置文件
vim ~/.jupyter/jupyter_notebook_config.py
其中需要修改的配置为
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha:***...刚才复制的那个密文'
c.NotebookApp.open_browser = False #默认不在本地浏览器中打开
c.NotebookApp.port =8888 #可随意指定一个端口
c.NotebookApp.notebook_dir ='/jupyter' #默认路径
贴上这段代码试试
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
会遇到的问题。
1.matplotlib的图像不显示。原本配置文件有这个选项,后来给取消了,官方建议是
use %pylab or %matplotlib in the notebook to enable matplotlib.
2.缺少库文件libc.so.6
yum install libX11
3.安装anaconda时依赖 bzip2
yum install bzip2
4.centos 安装pip
yum -y install epel-release
yum install python-pip
5.yum 不可用
vi /usr/bin/yum #第一行改为#!/usr/bin/python2.7
vi /usr/libexec/urlgrabber-ext-down #第一行改为#!/usr/bin/python2.7
6.Cannot remove entries from nonexistent file /opt/anaconda2/lib/python2.7/site-packages/easy-install.pth
官方说是一个bug解决方案是
curl https://bootstrap.pypa.io/ez_setup.py -o - | /opt/anaconda2/bin/python #python路径
附带jupyter for ubuntu的Dockerfile(经过测试ananocda for Linux 3-4.1.1 2-4.1.1均可)
<密码需要自己加入
curl https://bootstrap.pypa.io/ez_setup.py -o - | /opt/anaconda2/bin/python #跟python路径
FROM ubuntu:latest
MAINTAINER becivells <becivells@gmail.com>
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y bzip2 curl wget
ENV ANACONDA_VERSION 2-4.0.0-Linux-x86_64
ENV INSTALL_PATH /opt/anaconda2
RUN cd /tmp/ && wget https://repo.continuum.io/archive/Anaconda${ANACONDA_VERSION}.sh
RUN mkdir /jupyter && cd /tmp/ && bash Anaconda${ANACONDA_VERSION}.sh -b -p ${INSTALL_PATH} \
&& ${INSTALL_PATH}/bin/pip install -U pip \
#fix Anacondabug 2-4.0.0-Linux-x86_64
&&curl https://bootstrap.pypa.io/ez_setup.py -o - | ${INSTALL_PATH}/bin/python \
&&${INSTALL_PATH}/bin/pip install -U notebook \
&& ${INSTALL_PATH}/bin/jupyter notebook --generate-config \
&& echo "c.NotebookApp.ip='*'" >> ~/.jupyter/jupyter_notebook_config.py \
&& echo "c.NotebookApp.password = u'sha1:eddad9e86314:**************************************be'">> ~/.jupyter/jupyter_notebook_config.py \
&& echo "c.NotebookApp.open_browser = False" >> ~/.jupyter/jupyter_notebook_config.py \
&& echo "c.NotebookApp.port =8888" >> ~/.jupyter/jupyter_notebook_config.py \
&& echo "c.NotebookApp.notebook_dir ='/jupyter'" >> ~/.jupyter/jupyter_notebook_config.py \
&& rm -rf /tmp/* && apt-get autoclean && ln -s ${INSTALL_PATH} /opt/anaconda
EXPOSE 8888
CMD ["/opt/anaconda/bin/jupyter","notebook"]