cenos7上部署python3环境以及mysqlconnector2.1.5
本机的python2不要管他,因为可能有程序依赖目前的python2环境,比如yum!!!!!
一。安装python3依赖环境:
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
1.下载python3安装包
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
2.安装python3(创建安装目录-->解压安装包-->进入解压目录-->编译安装)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 mkdir -p /usr/local/python3
2
3 tar -zxvf Python-3.6.1.tgz
4 cd Python-3.6.1
5
6 ./configure --prefix=/usr/local/python3
7 make && make install
3.建立python3软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
5. 并将/usr/local/python3/bin加入PATH
# vim ~/.bash_profile
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # .bash_profile
2
3 # Get the aliases and functions
4 if [ -f ~/.bashrc ]; then
5 . ~/.bashrc
6 fi
7
8 # User specific environment and startup programs
9
10 PATH=$PATH:$HOME/bin:/usr/local/python3/bin
11
12 export PATH
修改完记得执行下面的命令,让修改的生效:
# source ~/.bash_profile
6.检查Python3及pip3是否正常可用
# python3 -V
Python 3.6.1
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
注意:不行的话在创建一下pip3的软链接
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
二。安装pip以及setuptools
1、安装pip前需要前置安装setuptools
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
2
3 tar -zxvf setuptools-19.6.tar.gz
4
5 cd setuptools-19.6
6
7 python3 setup.py build
8
9 python3 setup.py install
注意:报错: RuntimeError: Compression requires the (missing) zlib module
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 我们需要在linux中安装zlib-devel包,进行支持。
2 yum install zlib-devel
3
4 需要对python3.6进行重新编译安装。
5 cd python3.6.1
6 make && make install
7 又是漫长的编译安装过程。
8
9 重新安装setuptools
10 python3 setup.py build
11 python3 setup.py install
2.安装pip
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
2
3 tar -zxvf pip-8.0.2.tar.gz
4
5 cd pip-8.0.2
6 python3 setup.py build
7 python3 setup.py install
pip安装命令:
pip3 install paramiko
注意:报错:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 yum install openssl
2
3 yum install openssl-devel
4
5 cd python3.6.1
6
7 make && make install
三.安装支持Python3的mysqlconnector2.1.5
1.查看python3安装位置命令:
[root@apps mnt]# whereis python3
python3: /usr/bin/python3 /usr/local/python3
2.注意事项以及安装命令:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 这里有个问题容易迷惑人,因为系统中python2和3并存,下载的mysqlconnector RPM包安装的时候会自动安装到python2的库目录里面去,所以用的是mysqlconnector源码安装的方法,用python3命令去调用安装,这样就可以给python3装上这个包了。
2
3
4 wget https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.5.tar.gz --no-check-certificate
5
6 tar -zxvf mysql-connector-python-2.1.5.tar.gz
7 cd mysql-connector-python-2.1.5
8 python3 setup.py install
3.测试是否安装成功:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 [root@apps mnt]# python3
2 Python 3.6.1 (default, Nov 20 2018, 15:27:00)
3 [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
4 Type "help", "copyright", "credits" or "license" for more information.
5 >>> from distutils.sysconfig import get_python_lib
6 >>> print(get_python_lib())
7 /usr/local/python3/lib/python3.6/site-packages
8 >>> import mysql.connector#这里不报错就说明connector已经安装成功可以导入了