目录
===============================================================================
-
安装Python的依赖包
yum -y install openssl-devel sqlite-devel bzip2-devel ncurses-devel gdbm-devel readline-devel tcl-devel tk-devel xz-devel zlib-devel db4-devel libpcap-devel
-
编译环境准备
yum groupinstall 'Development Tools' -y
yum install zlib-devel bzip2-devel openssl-devel ncurese-devel -y
-
下载Python3.5的源码包并编译
cd /usr/local/src
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
(前提条件---安装wget: yum install wget)
tar -zxf /usr/local/src/Python-3.5.1.tgz && cd Python-3.5.1
-
创建安装目录
mkdir /opt/python3.5
-
编译安装
./configure --prefix=/opt/python3.5 --enable-shared
make && make install
-
创建Python3链接
ln -s /opt/python3.5/bin/python3 /usr/bin/python3
echo "/opt/python3.5/lib" > /etc/ld.so.conf.d/python3.5.conf
ldconfig
-
检测python3.5是否安装成功
python3 --version
因为python3.5自带pip,setuptools,只需升级即可
-
创建Pip3链接
保留pip指向Pip2,创建pip3的软链接指向Pip3
ln -s /opt/python3.5/bin/pip3 /usr/bin/pip3
-
升级pip(可选)
/opt/python3.5/bin/pip3 install --upgrade pip
-
升级setuptools(可选)
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3
ln -s /opt/python3.5/bin/easy_install /usr/bin/easy_install
安装模块
pip install Numpy
pip install scipy
pip install matplotlib
pip install scikit-learn
pip install pandas
pip install keras
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
安装配置jupyter
https://www.jianshu.com/p/7e7a14732cf9
安装jupyter
[root@AIcentos7 code1]# pip3 install jupyter
提速:pip3 install jupyter -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
生成配置文件
生成配置文件jupyter notebook --generate-config,这个命令会在当前用户的 ~/.jupyter/ 文件夹下面生成一个 jupyter_notebook_config.py 文件
[root@AIcentos7 code1]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
配置并生成NotebookApp.password的密文
[root@AIcentos7 code1]# python3
Python 3.5.1 (default, Oct 8 2018, 15:12:06)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd
>>> passwd()
Enter password: 123456
Verify password: 123456
'sha1:93612d137403:2e3076230435b845f1dbb969bff3008d98fdb551'
sha1:cdf8084ef441:a2ea5ec9a39e6a12ce49a94dec7f72a2e59b139c
>>> quit()
生成测试证书mycert.pem
此命令会在你的当前文件夹生成mycert.pem文件
[root@AIcentos7 jupyterroot]# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem
Generating a 2048 bit RSA private key
..................................................+++
......................................+++
writing new private key to 'mycert.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:guangdong
Locality Name (eg, city) [Default City]:sz
Organization Name (eg, company) [Default Company Ltd]:kd
Organizational Unit Name (eg, section) []:hightech
Common Name (eg, your name or your server's hostname) []:AIcentos7
Email Address []:zyp361161@163.com
[root@AIcentos7 jupyterroot]# find / -name mycert.pem
/root/AI/jupyterroot/mycert.pem
编辑配置文件
[root@AIcentos7 code1]# cp -ip /root/.jupyter/jupyter_notebook_config.py /root/.jupyter/jupyter_notebook_config.py.org
[root@AIcentos7 code1]# vi /root/.jupyter/jupyter_notebook_config.py
设置以下内容:
c.NotebookApp.ip='*' # 就是设置所有ip皆可访问
c.NotebookApp.password = u'sha:ce...' # notebook.auth 生成的那个密文'
c.NotebookApp.open_browser = False # 禁止自动打开浏览器
c.NotebookApp.port =8888 #随便指定一个端口
c.NotebookApp.notebook_dir = u'' # 指定工作目录
c.NotebookApp.certfile = 'u'路径名/mycert.pem'' #指定证书位置
[root@AIcentos7 jupyterroot]# diff /root/.jupyter/jupyter_notebook_config.py /root/.jupyter/jupyter_notebook_config.py.org
102c102
< c.NotebookApp.certfile = '/root/AI/jupyterroot/mycert.pem'
---
> #c.NotebookApp.certfile = ''
261c261
< c.NotebookApp.notebook_dir = '/root/AI/jupyterroot'
---
> #c.NotebookApp.notebook_dir = ''
267c267
< c.NotebookApp.open_browser = True
---
> #c.NotebookApp.open_browser = True
276c276
< c.NotebookApp.password = 'sha1:cdf8084ef441:a2ea5ec9a39e6a12ce49a94dec7f72a2e59b139c'
---
> #c.NotebookApp.password = ''
287c287
< c.NotebookApp.port = 8888
---
> #c.NotebookApp.port = 8888
[root@AIcentos7 jupyterroot]#
测试启动juputer
[root@AIcentos7 jupyterroot]# jupyter notebook --allow-root
https://ip:8888/tree访问 ,密码:123456
c.NotebookApp.certfile = '/root/.jupyter/jcert.pem'
c.NotebookApp.ip = '172.20.110.38'
c.NotebookApp.keyfile = '/root/.jupyter/jkey.key'
c.NotebookApp.notebook_dir = '/tmp/AIstudy'
c.NotebookApp.open_browser = False
c.NotebookApp.password = 'sha1:a3beed621745:aa70c10d906e250b85b69ff2e28b7bd7a9e77b83'
c.NotebookApp.port = 8888
c.ContentsManager.root_dir = '/tmp/AIstudy/'
=================================================================================================
报错处理
报错一
[root@AIcentos7 ~]# ln -s /opt/python3.5/bin/easy_install /usr/bin/easy_install
ln: failed to create symbolic link ?.usr/bin/easy_install?. File exists
[root@AIcentos7 ~]# cp -ip /usr/bin/easy_install /usr/bin/easy_install.bk
[root@AIcentos7 ~]# rm -rf /usr/bin/easy_install
[root@AIcentos7 ~]# ln -s /opt/python3.5/bin/easy_install /usr/bin/easy_install
报错二
安装包出现timeout?
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError
解决办法:pip3 install pip-autoremove -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
扩展:通过几次pip的使用,对于默认的pip源的速度实在无法忍受,于是便搜集了一些国内的pip源,如下:
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
使用方法很简单,直接 -i 加 url 即可!如下:
pip3 install jupyter -i http://pypi.douban.com/simple
报错三
jupyter notebook看不到新建python3
解决办法:pip3 install jupyter notebook
报错四
启动jupyter notebook报错:“ImportError: cannot import name 'Type'“
解决办法:降低版本tornado==5.1.1(默认安装的版本是6.0.4)
降级tornado版本:
pip install tornado==5.1.1 -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com