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(创建安装目录-->解压安装包-->进入解压目录-->编译安装)
 mkdir -p /usr/local/python3

 tar -zxvf Python-3.6.1.tgz
cd Python-3.6.1 ./configure --prefix=/usr/local/python3
make && make install

安装命令

3.建立python3软连接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
5. 并将/usr/local/python3/bin加入PATH
# vim ~/.bash_profile
 # .bash_profile

 # Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/python3/bin 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
 wget --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

 tar -zxvf setuptools-19.6.tar.gz

 cd setuptools-19.6

 python3 setup.py build

 python3 setup.py install

安装命令

注意:报错: RuntimeError: Compression requires the (missing) zlib module

 我们需要在linux中安装zlib-devel包,进行支持。
yum install zlib-devel 需要对python3.6进行重新编译安装。
cd python3.6.1
make && make install
又是漫长的编译安装过程。 重新安装setuptools
python3 setup.py build
python3 setup.py install

解决办法

2.安装pip

 wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

 tar -zxvf pip-8.0.2.tar.gz

 cd pip-8.0.2
python3 setup.py build
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.

 yum install openssl

 yum install openssl-devel

 cd python3.6.1

 make && make install

解决办法

三.安装支持Python3的mysqlconnector2.1.5

1.查看python3安装位置命令:

[root@apps mnt]# whereis python3
python3: /usr/bin/python3 /usr/local/python3

2.注意事项以及安装命令:

 这里有个问题容易迷惑人,因为系统中python2和3并存,下载的mysqlconnector RPM包安装的时候会自动安装到python2的库目录里面去,所以用的是mysqlconnector源码安装的方法,用python3命令去调用安装,这样就可以给python3装上这个包了。

 wget https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.5.tar.gz --no-check-certificate

 tar -zxvf mysql-connector-python-2.1.5.tar.gz
cd mysql-connector-python-2.1.5
python3 setup.py install

安装注意事宜!

3.测试是否安装成功:

 [root@apps mnt]# python3
Python 3.6.1 (default, Nov 20 2018, 15:27:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.sysconfig import get_python_lib
>>> print(get_python_lib())
/usr/local/python3/lib/python3.6/site-packages
>>> import mysql.connector#这里不报错就说明connector已经安装成功可以导入了

测试导入模块操作

上一篇:如何在CentOS 7上搭建LAMP环境(使用YUM或编译)


下一篇:在Linux上部署Kettle环境