先查看以下两篇博客:
腾讯云安装python36和pip3、Tensorflow
yum下载安装包但不安装
上面介绍了在线安装python36和pip3、Tensorflow的方法,离线安装时的方法类似在线安装,但得记录yum和pip包的依赖和记录。
总纲
本文分两条路线走,第一条是通过在线安装下载需要的yum包和pip包,记录yum依赖和pip依赖,第二条路线是离线安装下载好的yum包(python和pip依赖)、编译安装python、离线安装pip包及其依赖。
一、在线安装
在线安装的目的是下载yum包并记录其依赖。
1. 修改yum配置,使其记录依赖并缓存rpm包
yum的配置文件在:/etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
修改其中keepcache和logfile配置
keepcache=1
logfile=/var/log/yum.log
同时可以看到默认的rpm包缓存目录为
cachedir=/var/cache/yum/$basearch/$releasever
2. 清空yum缓存和log
直接rm缓存和log
3. 安装python依赖、记录log,查看依赖记录
yum install zlib-devel openssl-devel
如果不安装zlib-devel则在编译python的时候会报错说少了zlib-devel依赖
如果不安装openssl-devel的话则在通过requiments.txt安装依赖的时候会报错
Collecting tornado==5.1 (from -r requirements.txt (line 87))
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-_ppe8j7p/tornado/setup.py", line 18, in <module>
import ssl
File "/usr/local/Python36/lib/python3.6/ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
暂时列举这一个安装包,在make的时候报错提示缺少什么依赖就添加什么依赖
若需要其他依赖就去安装
可以看到相关的记录中安装了zlib-devel,并更新了zlib
Nov 13 15:09:06 Updated: zlib-1.2.7-17.el7.x86_64
Nov 13 15:09:07 Installed: zlib-devel-1.2.7-17.el7.x86_64
Nov 13 15:09:07 Updated: zlib-1.2.7-17.el7.i686
同时在yum的缓存目录下看到新增加的几个rpm包
[root@VM_0_12_centos 7]# ls -l /var/cache/yum/x86_64/7/os/packages/
total 532
-rw-r--r-- 1 root root 92752 Nov 21 2016 zlib-1.2.7-17.el7.i686.rpm
-rw-r--r-- 1 root root 91872 Nov 21 2016 zlib-1.2.7-17.el7.x86_64.rpm
-rw-r--r-- 1 root root 51044 Nov 21 2016 zlib-devel-1.2.7-17.el7.x86_64.rpm
拷贝这几个rpm包,并拷贝log(因为log中是通过时间显示的,方便我们离线安装时按照依赖关系先后安装)
4. 编译安装Python36,并设置python3和pip3软连接
略,具体操作查看腾讯云安装python36和pip3、Tensorflow
5.通过pip3安装Tensorflow
先下载后安装
- 下载Tenorflow的依赖时,先要生成requiments.txt,然后通过requiments.txt
pip3 freeze >requirements.txt
它会递归查找.py文件并将其依赖写入requirements.txt
absl-py==0.4.0
astor==0.7.1
backcall==0.1.0
beautifulsoup4==4.6.3
bleach==2.1.4
bs4==0.0.1
certifi==2018.8.13
chardet==3.0.4
colorama==0.3.9
configparser==3.5.0
cycler==0.10.0
DateTime==4.2
decorator==4.3.0
entrypoints==0.2.3
future==0.16.0
gast==0.2.0
graphviz==0.10.1
grpcio==1.14.1
h5py==2.8.0
html5lib==1.0.1
idna==2.7
ipykernel==4.9.0
ipython==6.5.0
ipython-genutils==0.2.0
ipywidgets==7.4.1
itchat==1.2.32
jedi==0.12.1
Jinja2==2.10
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-core==4.4.0
Keras==2.2.2
Keras-Applications==1.0.4
Keras-Preprocessing==1.0.2
kiwisolver==1.0.1
lxml==4.2.4
Markdown==2.6.11
MarkupSafe==1.0
matplotlib==2.2.3
mistune==0.8.3
msgpack==0.5.6
nbconvert==5.3.1
nbformat==4.4.0
notebook==5.6.0
numpy==1.14.5
objgraph==3.4.0
pandas==0.23.4
pandas-datareader==0.6.0
pandocfilters==1.4.2
parso==0.3.1
patsy==0.5.0
pickleshare==0.7.4
Pillow==5.2.0
plotly==3.1.1
prometheus-client==0.3.1
prompt-toolkit==1.0.15
protobuf==3.6.1
Pygments==2.2.0
pyparsing==2.2.0
pypng==0.0.18
PyQRCode==1.2.1
python-dateutil==2.7.3
pytz==2018.5
pywinpty==0.5.4
PyYAML==3.13
pyzmq==17.1.2
qtconsole==4.4.1
requests==2.19.1
requests-file==1.4.3
requests-ftp==0.3.1
retrying==1.3.3
scikit-learn==0.19.2
scipy==1.1.0
seaborn==0.9.0
Send2Trash==1.5.0
simplegeneric==0.8.1
simplejson==3.16.0
six==1.11.0
statsmodels==0.9.0
tensorboard==1.10.0
tensorflow==1.10.0
termcolor==1.1.0
terminado==0.8.1
testpath==0.3.1
tornado==5.1
traitlets==4.3.2
tushare==1.2.12
urllib3==1.23
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.14.1
widgetsnbextension==3.4.1
wrapt==1.10.11
wxpy==0.3.9.8
zope.interface==4.5.0
- 通过requirements.txt下载依赖包
pip3 download -r requirements.txt -d /var/cache/pip3/
[root@VM_0_12_centos pip3]# ls
absl-py-0.4.0.tar.gz jupyter_client-5.2.3-py2.py3-none-any.whl pyparsing-2.2.0-py2.py3-none-any.whl
astor-0.7.1-py2.py3-none-any.whl jupyter_console-5.2.0-py2.py3-none-any.whl pypng-0.0.18.tar.gz
backcall-0.1.0.zip jupyter_core-4.4.0-py2.py3-none-any.whl PyQRCode-1.2.1.zip
beautifulsoup4-4.6.3-py3-none-any.whl Keras-2.2.2-py2.py3-none-any.whl python_dateutil-2.7.3-py2.py3-none-any.whl
bleach-2.1.4-py2.py3-none-any.whl Keras_Applications-1.0.4-py2.py3-none-any.whl pytz-2018.5-py2.py3-none-any.whl
bs4-0.0.1.tar.gz Keras_Preprocessing-1.0.2-py2.py3-none-any.whl pywinpty-0.5.4.tar.gz
certifi-2018.8.13-py2.py3-none-any.whl kiwisolver-1.0.1-cp36-cp36m-manylinux1_x86_64.whl PyYAML-3.13.tar.gz
chardet-3.0.4-py2.py3-none-any.whl lxml-4.2.4-cp36-cp36m-manylinux1_x86_64.whl pyzmq-17.1.2-cp36-cp36m-manylinux1_x86_64.whl
colorama-0.3.9-py2.py3-none-any.whl Markdown-2.6.11-py2.py3-none-any.whl qtconsole-4.4.1-py2.py3-none-any.whl
configparser-3.5.0.tar.gz MarkupSafe-1.0.tar.gz requests-2.19.1-py2.py3-none-any.whl
cycler-0.10.0-py2.py3-none-any.whl matplotlib-2.2.3-cp36-cp36m-manylinux1_x86_64.whl requests_file-1.4.3-py2.py3-none-any.whl
DateTime-4.2-py2.py3-none-any.whl mistune-0.8.3-py2.py3-none-any.whl requests-ftp-0.3.1.tar.gz
decorator-4.3.0-py2.py3-none-any.whl msgpack-0.5.6-cp36-cp36m-manylinux1_x86_64.whl requirements.txt
entrypoints-0.2.3-py2.py3-none-any.whl nbconvert-5.3.1-py2.py3-none-any.whl retrying-1.3.3.tar.gz
future-0.16.0.tar.gz nbformat-4.4.0-py2.py3-none-any.whl scikit_learn-0.19.2-cp36-cp36m-manylinux1_x86_64.whl
gast-0.2.0.tar.gz notebook-5.6.0-py2.py3-none-any.whl scipy-1.1.0-cp36-cp36m-manylinux1_x86_64.whl
graphviz-0.10.1-py2.py3-none-any.whl numpy-1.14.5-cp36-cp36m-manylinux1_x86_64.whl seaborn-0.9.0-py3-none-any.whl
grpcio-1.14.1-cp36-cp36m-manylinux1_x86_64.whl objgraph-3.4.0-py2.py3-none-any.whl Send2Trash-1.5.0-py3-none-any.whl
h5py-2.8.0-cp36-cp36m-manylinux1_x86_64.whl pandas-0.23.4-cp36-cp36m-manylinux1_x86_64.whl simplegeneric-0.8.1.zip
html5lib-1.0.1-py2.py3-none-any.whl pandas_datareader-0.6.0-py2.py3-none-any.whl simplejson-3.16.0.tar.gz
idna-2.7-py2.py3-none-any.whl pandocfilters-1.4.2.tar.gz six-1.11.0-py2.py3-none-any.whl
ipykernel-4.9.0-py3-none-any.whl parso-0.3.1-py2.py3-none-any.whl statsmodels-0.9.0-cp36-cp36m-manylinux1_x86_64.whl
ipython-6.5.0-py3-none-any.whl patsy-0.5.0-py2.py3-none-any.whl tensorboard-1.10.0-py3-none-any.whl
ipython_genutils-0.2.0-py2.py3-none-any.whl pickleshare-0.7.4-py2.py3-none-any.whl tensorflow-1.10.0-cp36-cp36m-manylinux1_x86_64.whl
ipywidgets-7.4.1-py2.py3-none-any.whl Pillow-5.2.0-cp36-cp36m-manylinux1_x86_64.whl termcolor-1.1.0.tar.gz
itchat-1.2.32-py2.py3-none-any.whl plotly-3.1.1-py2.py3-none-any.whl terminado-0.8.1-py2.py3-none-any.whl
jedi-0.12.1-py2.py3-none-any.whl prometheus_client-0.3.1.tar.gz testpath-0.3.1-py2.py3-none-any.whl
Jinja2-2.10-py2.py3-none-any.whl prompt_toolkit-1.0.15-py3-none-any.whl tornado-5.1.tar.gz
jsonschema-2.6.0-py2.py3-none-any.whl protobuf-3.6.1-cp36-cp36m-manylinux1_x86_64.whl
jupyter-1.0.0-py2.py3-none-any.whl Pygments-2.2.0-py2.py3-none-any.whl
- 通过requiments.txt安装pip包
先安装yum install openssl-devel,否则在通过requirements.txt安装的时候会报以下错误:
[root@VM_0_12_centos pip3]# pip3 install --no-index --find-links=/var/cache/pip3 -r requirements.txt
Looking in links: /var/cache/pip3
Collecting absl-py==0.4.0 (from -r requirements.txt (line 1))
Collecting astor==0.7.1 (from -r requirements.txt (line 2))
Collecting backcall==0.1.0 (from -r requirements.txt (line 3))
Collecting beautifulsoup4==4.6.3 (from -r requirements.txt (line 4))
Collecting bleach==2.1.4 (from -r requirements.txt (line 5))
Collecting bs4==0.0.1 (from -r requirements.txt (line 6))
Collecting certifi==2018.8.13 (from -r requirements.txt (line 7))
Collecting chardet==3.0.4 (from -r requirements.txt (line 8))
Collecting colorama==0.3.9 (from -r requirements.txt (line 9))
Collecting configparser==3.5.0 (from -r requirements.txt (line 10))
Collecting cycler==0.10.0 (from -r requirements.txt (line 11))
Collecting DateTime==4.2 (from -r requirements.txt (line 12))
Collecting decorator==4.3.0 (from -r requirements.txt (line 13))
Collecting entrypoints==0.2.3 (from -r requirements.txt (line 14))
Collecting future==0.16.0 (from -r requirements.txt (line 15))
Collecting gast==0.2.0 (from -r requirements.txt (line 16))
Collecting graphviz==0.10.1 (from -r requirements.txt (line 17))
Collecting grpcio==1.14.1 (from -r requirements.txt (line 18))
Collecting h5py==2.8.0 (from -r requirements.txt (line 19))
Collecting html5lib==1.0.1 (from -r requirements.txt (line 20))
Collecting idna==2.7 (from -r requirements.txt (line 21))
Collecting ipykernel==4.9.0 (from -r requirements.txt (line 22))
Collecting ipython==6.5.0 (from -r requirements.txt (line 23))
Collecting ipython-genutils==0.2.0 (from -r requirements.txt (line 24))
Collecting ipywidgets==7.4.1 (from -r requirements.txt (line 25))
Collecting itchat==1.2.32 (from -r requirements.txt (line 26))
Collecting jedi==0.12.1 (from -r requirements.txt (line 27))
Collecting Jinja2==2.10 (from -r requirements.txt (line 28))
Collecting jsonschema==2.6.0 (from -r requirements.txt (line 29))
Collecting jupyter==1.0.0 (from -r requirements.txt (line 30))
Collecting jupyter-client==5.2.3 (from -r requirements.txt (line 31))
Collecting jupyter-console==5.2.0 (from -r requirements.txt (line 32))
Collecting jupyter-core==4.4.0 (from -r requirements.txt (line 33))
Collecting Keras==2.2.2 (from -r requirements.txt (line 34))
Collecting Keras-Applications==1.0.4 (from -r requirements.txt (line 35))
Collecting Keras-Preprocessing==1.0.2 (from -r requirements.txt (line 36))
Collecting kiwisolver==1.0.1 (from -r requirements.txt (line 37))
Collecting lxml==4.2.4 (from -r requirements.txt (line 38))
Collecting Markdown==2.6.11 (from -r requirements.txt (line 39))
Collecting MarkupSafe==1.0 (from -r requirements.txt (line 40))
Collecting matplotlib==2.2.3 (from -r requirements.txt (line 41))
Collecting mistune==0.8.3 (from -r requirements.txt (line 42))
Collecting msgpack==0.5.6 (from -r requirements.txt (line 43))
Collecting nbconvert==5.3.1 (from -r requirements.txt (line 44))
Collecting nbformat==4.4.0 (from -r requirements.txt (line 45))
Collecting notebook==5.6.0 (from -r requirements.txt (line 46))
Collecting numpy==1.14.5 (from -r requirements.txt (line 47))
Collecting objgraph==3.4.0 (from -r requirements.txt (line 48))
Collecting pandas==0.23.4 (from -r requirements.txt (line 49))
Collecting pandas-datareader==0.6.0 (from -r requirements.txt (line 50))
Collecting pandocfilters==1.4.2 (from -r requirements.txt (line 51))
Collecting parso==0.3.1 (from -r requirements.txt (line 52))
Collecting patsy==0.5.0 (from -r requirements.txt (line 53))
Collecting pickleshare==0.7.4 (from -r requirements.txt (line 54))
Collecting Pillow==5.2.0 (from -r requirements.txt (line 55))
Collecting plotly==3.1.1 (from -r requirements.txt (line 56))
Collecting prometheus-client==0.3.1 (from -r requirements.txt (line 57))
Collecting prompt-toolkit==1.0.15 (from -r requirements.txt (line 58))
Collecting protobuf==3.6.1 (from -r requirements.txt (line 59))
Collecting Pygments==2.2.0 (from -r requirements.txt (line 60))
Collecting pyparsing==2.2.0 (from -r requirements.txt (line 61))
Collecting pypng==0.0.18 (from -r requirements.txt (line 62))
Collecting PyQRCode==1.2.1 (from -r requirements.txt (line 63))
Collecting python-dateutil==2.7.3 (from -r requirements.txt (line 64))
Collecting pytz==2018.5 (from -r requirements.txt (line 65))
Collecting pywinpty==0.5.4 (from -r requirements.txt (line 66))
Collecting PyYAML==3.13 (from -r requirements.txt (line 67))
Collecting pyzmq==17.1.2 (from -r requirements.txt (line 68))
Collecting qtconsole==4.4.1 (from -r requirements.txt (line 69))
Collecting requests==2.19.1 (from -r requirements.txt (line 70))
Collecting requests-file==1.4.3 (from -r requirements.txt (line 71))
Collecting requests-ftp==0.3.1 (from -r requirements.txt (line 72))
Collecting retrying==1.3.3 (from -r requirements.txt (line 73))
Collecting scikit-learn==0.19.2 (from -r requirements.txt (line 74))
Collecting scipy==1.1.0 (from -r requirements.txt (line 75))
Collecting seaborn==0.9.0 (from -r requirements.txt (line 76))
Collecting Send2Trash==1.5.0 (from -r requirements.txt (line 77))
Collecting simplegeneric==0.8.1 (from -r requirements.txt (line 78))
Collecting simplejson==3.16.0 (from -r requirements.txt (line 79))
Collecting six==1.11.0 (from -r requirements.txt (line 80))
Collecting statsmodels==0.9.0 (from -r requirements.txt (line 81))
Collecting tensorboard==1.10.0 (from -r requirements.txt (line 82))
Collecting tensorflow==1.10.0 (from -r requirements.txt (line 83))
Collecting termcolor==1.1.0 (from -r requirements.txt (line 84))
Collecting terminado==0.8.1 (from -r requirements.txt (line 85))
Collecting testpath==0.3.1 (from -r requirements.txt (line 86))
Collecting tornado==5.1 (from -r requirements.txt (line 87))
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-_ppe8j7p/tornado/setup.py", line 18, in <module>
import ssl
File "/usr/local/Python36/lib/python3.6/ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-_ppe8j7p/tornado/
pip3 download setuptools -d /var/cache/pip3
pip3 install --no-index --find-links=/var/cache/pip3 setuptools-40.5.0-py2.py3-none-any.whl
通过pip3 download numpy
下载安装包
通过pip3 help download
查看pip3 download的几个参数,发现--cache-dir <dir>
参数可以指定缓存下载的包目录,否则的话会下载到当前目录下.
#创建pip3缓存目录
mkdir /var/cache/pip3
通过缓存文件安装numpy
pip3 install --no-index --find-links=file:/var/cache/pip3 numpy