赞
踩
目前服务器为centos6.9, 系统自带的python的版本为2.6.x,这时我们需要用到Python3 和 pip3,但是原有的Python2 和pip2也得用,也就是说python3 and python2 共存,pip2 and pip3共存,下面文章将会介绍:
1、先到官方网站下载python3的安装包
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz
2、解压包
tar -xf Python-3.6.6.tar.xz
3、安装依赖
- yum install openssl-devel -y
- yum install zlib-devel -y
- yum install libffi-devel -y
4、编译安装
- cd Python-3.9.10
- ./configure --prefix=/usr/local/Python-3.9.10 #安装目录可以自己定义无所谓。
- make && make install
5、编译完成后会在如 /opt/下生成Python的文件夹 ,自定义软连接:
ln -s /usr/local/Python-3.9.10/bin/python3 /usr/bin/python3
测试python3安装是否正常:
6、python3的安装已经完成,接下来给python3安装pip3
yum install python3-pip
7、测试是否安装成功
pip3 -V #检查版本
pip 8.0.2 from /opt/Python/lib/python3.6/site-packages/pip-8.0.2-py3.6.egg (python 3.6)
使用pip3安装pymysql模块
pip3 install pymysql
- [root@192.168.200.143 /opt/Python/bin]$ pip3 install pymysql
- Collecting pymysql
- Cache entry deserialization failed, entry ignored
- Cache entry deserialization failed, entry ignored
- Downloading https://files.pythonhosted.org/packages/a7/7d/682c4a7da195a678047c8f1c51bb7682aaedee1dca7547883c3993ca9282/PyMySQL-0.9.2-py2.py3-none-any.whl (47kB)
- 100% |████████████████████████████████| 49kB 349kB/s
- Requirement already satisfied (use --upgrade to upgrade): cryptography in /opt/Python/lib/python3.6/site-packages (from pymysql)
- Requirement already satisfied (use --upgrade to upgrade): six>=1.4.1 in /opt/Python/lib/python3.6/site-packages (from cryptography->pymysql)
- Requirement already satisfied (use --upgrade to upgrade): cffi!=1.11.3,>=1.7 in /opt/Python/lib/python3.6/site-packages (from cryptography->pymysql)
- Requirement already satisfied (use --upgrade to upgrade): idna>=2.1 in /opt/Python/lib/python3.6/site-packages (from cryptography->pymysql)
- Requirement already satisfied (use --upgrade to upgrade): asn1crypto>=0.21.0 in /opt/Python/lib/python3.6/site-packages (from cryptography->pymysql)
- Requirement already satisfied (use --upgrade to upgrade): pycparser in /opt/Python/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.7->cryptography->pymysql)
- Installing collected packages: pymysql
- Successfully installed pymysql-0.9.2
- You are using pip version 8.0.2, however version 18.0 is available.
- You should consider upgrading via the 'pip install --upgrade pip' command.
安装完毕后,进入到python3查看使用pip3安装的pymysql模块是否可以被python3导入:
- [root@192.168.200.143 /opt/Python/bin]$ python3
- Python 3.6.6 (default, Jul 27 2018, 02:57:12)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import pymysql
- >>> exit(
OK 完成 ~~
8、报错 "error: metadata-generation-failed"
解决方法:pip3 install --upgrade setuptools
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。