程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Process notes for upgrading Python from 3.6 to 3.8 and deploying tensorflow2 based on centos7 environment

編輯:Python

0. Preface

primary Python The computing environment is Python3.6 edition , And based on 3.6 Of Tensoflow1.13, because Python3.6 There is no support , therefore , Now upgrade to 3.8.

1. Python from 3.6 Upgrade to 3.8

1. First install the dependency package , Install the corresponding compiler tool
Because it is an upgrade ,CentOS Environmental dependency already exists , Skip this step .

[[email protected] bin]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-de

2. Download installation package
Under the current user , Download the installation package to software Under the folder , There are two ways to download :

  • One is to manually download directly from the official website :
    https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tgz

  • Second, command acquisition :

[[email protected] python]# cd software
[[email protected] software]$ wget http://www.python.org/ftp/python/3.8.13/Python-3.8.13.tgz

3. decompression

[[email protected] software]# tar zxvf Python-3.8.13.tgz

4. Back up and modify the original python3(3.6 edition )

[[email protected] software]# cd /usr/local
[[email protected] local]# mv python3 python3.6

5. Create build install directory

[[email protected] local]# mkdir /usr/local/python3
[[email protected] local]# ls
bin etc games include lib lib64 libexec python3 python3.6 sbin share src

6. install
Specify the path to install

[[email protected] local]# cd /home/python/software/Python-3.8.13
[[email protected] Python-3.8.13]# ./configure --prefix=/usr/local/python3

compile

[[email protected] Python-3.8.13]# make

Report errors :

/home/python/software/Python-3.8.13/Modules/_ctypes/_ctypes.c:107:17: Fatal error :ffi.h: There is no file or directory
Compile interrupt .

Solution :

[[email protected] Python-3.8.13]# yum install libffi-devel

install

[[email protected] Python-3.8.13]# make install

7. Create soft link
Because it is an upgrade , It has been previously defined , You can skip this step .

[[email protected] bin]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[[email protected] bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

It is necessary to verify whether the original definition is valid .

[[email protected] bin]# ls -l /usr/bin/python3
/usr/bin/python3 -> /usr/local/python3/bin/python3
[[email protected] bin]# ls -l /usr/bin/pip3
/usr/bin/pip3 -> /usr/local/python3/bin/pip3

8. Verify success

python3 -V
pip3 -V

9. Configure environment variables 【 Optional 】

[[email protected] bin]# vi ~/.bash_profile

Edit profile

export PYTHON_HOME=/usr/local/python3
export PATH=$PYTHON_HOME/bin:$PATH

Execute configuration file , take effect

[[email protected] bin]# source ~/.bash_profile
[[email protected] bin]# echo $PYTHON_HOME
/usr/local/python3

2. python tool kit 、 Algorithm framework installation

2.1. Tensorflow2 Environmental installation

install tensorflow2.6, rely on numpy1.19.5 edition .

# install numpy1.19.5
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.19.5
# Install image dependencies imageio2.9.0
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple imageio==2.9.0
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-image
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==2.6.1

2.2. Data analysis environment installation

2.2.1 Data analysis

# Numerical calculation package
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scipy
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-learn
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple seaborn
# Bayesian optimization package
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple bayesian-optimization

2.2.2. Machine learning ensemble algorithm XGBoost install

XGBoost The new version needs to rely on cmake3.15 Above version , as well as gcc5.0 Above version , upgrade cmake and gcc The process is as follows , The upgrade process directly skips .

[[email protected] Downloads]# wget https://cmake.org/files/v3.17/cmake-3.17.1.tar.gz
[[email protected] Downloads]# tar -zxvf cmake-3.17.1.tar.gz
[[email protected] Downloads]# cd cmake-3.17.1
[[email protected] cmake-3.17.1]# ./bootstrap --prefix=/usr
CMake has bootstrapped. Now run gmake.
[[email protected] cmake-3.17.1]# gmake
[[email protected] cmake-3.17.1]# gmake install
upgrade gcc To 5.x
If installed , You can skip :
[[email protected] Downloads]# yum install bzip2
[[email protected] Downloads]# wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.bz2
[[email protected] Downloads]# tar -jxvf gcc-5.4.0.tar.bz2
[[email protected] gcc-5.4.0]# cd gcc-5.4.0
[[email protected] gcc-5.4.0]# ./contrib/download_prerequisites
[[email protected] bin]# /home/python/Downloads/gcc-5.4.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
[[email protected] bin]# make
[[email protected] bin]# make install
Keep it 4.8.5 Of gcc, When you need to go back later , It's a lot easier
[[email protected] bin]# mv gcc gcc-4.85
[[email protected] bin]# mv g++ g++-4.85
[[email protected] bin]# mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6-4.85
The reference processing is changed to the new version
[[email protected] bin]# ln -s /usr/local/bin/gcc /usr/bin/gcc
[[email protected] bin]# ln -s /usr/local/bin/g++ /usr/bin/g++
[[email protected] bin]# ln /usr/local/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6

install xgboost.

[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple xgboost

2.3. Visualization and Web Service pack installation

[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple flask
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple tornado
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple streamlit==1.9.1

streamlit 1.10 Version and above tensorflow2 Conflict :
tensorflow 2.6.1 requires typing-extensions~=3.7.4, but you have typing-extensions 4.2.0 which is incompatible.

2.4. Database interface

[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pymongo
[[email protected] bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple clickhouse_driver

3. other

3.1. uninstall python3.6

When uninstalling, directly put the ⽬ Just delete the record :

 rm -rf /usr/local/python3.6

3.2. Pydev Configuration modification

about Eclispe plug-in unit PyDev The configuration is as follows :

PyDev/Interpreters/Python Interpreter in , adopt “Browse for python/pypy.exe” Button to replace the original “/usr/local/python3/bin/python3.6” by “/usr/local/python3/bin/python3.8”.

4. summary

Python Upgrading is easy , Many environmental dependencies already exist , Just reinstall the new version Python Can , But the algorithm calculation package should be upgraded with caution .

  • Recommendation 1 : The computing environment and the visual environment should preferably be independent of each other , Independent ;
  • Recommendation two :Tensorflow Special environmental requirements , You need to determine the version and dependency in advance , for example Tensorflow2.6, rely on numpy1.19.5、imageio2.9.0、typing-extensions3.7.4 etc. .

Reference resources :

[1]. Xiao Yongwei . be based on CentOS7 install Python3 Computing environment and PyDev(Eclipse) Development tool logs (2021 year ). CSDN Blog . 2021.04
[2]. Knowledge sky Gang Ru Wei 00. linux load and unload python3 . Baidu library
[3]. weixin_39892615. python There is no file or directory _ Fatal error :python.h: There is no file or directory . CSDN Blog . 2020.11


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved