linux7.4安装python3.8.3

阿里云Linux7.4安装python3.8.3
下载python3.8

wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz

别问,先安装依赖

yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

解压python压缩包更名python3,路径/usr/local/python3.8
配置、编译、安装

./configure --prefix=/usr/local/python3.8
make && make install

删除原自带python2.7版本软链接,重新建立3.8软链接

rm -rf /usr/bin/python
ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python
pip3软链接
ln -s /usr/local/python3.8/bin/pip3 /usr/bin/pip3

将版本python3.8.3命令加入环境变量

vi /etc/profile
#将这句加到文件最下面
export PATH=$PATH:/usr/local/python3.8/bin
# 刷新配置
source /etc/profile

完犊子,yum失效了,python3不搭yum,改

vi /usr/bin/yum
#!/usr/bin/python 修改成 #!/usr/bin/python2.7

根据需求:升级pip,pip3至最新

pip3 install --upgrade pip
pip install --upgrade pip

Linux下安装MySQL-python

pip3 install MySQL-python

报错1:
linux7.4安装python3.8.3_第1张图片

/usr/local/python3.8/lib/python3.8/configparser.py
改为:ConfigParser.py

报错2:
linux7.4安装python3.8.3_第2张图片
搞不了搞不了,换

MySQLdb 只适用于python2.x
python3.x 用pymysql
安装命令:pip3 install pymysql
使用:import pymysql

pymysql转MySQL-python[未校验]
django+mysql
Django默认的还是使用MySQLdb:执行会报:ImportError: No module named ‘MySQLdb’
在站点的 init.py 文件中添加

import pymysql
pymysql.install_as_MySQLdb()

win下安装MySQL-python
找对应python版本及系统的mysqlclient…whl并下载

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

linux7.4安装python3.8.3_第3张图片
dos模式至存放xxx.whl文件的目录,运行

pip install mysqlclient-1.4.6-cp38-cp38-win32.whl

下图提示,安装成功。import MySQLdb可以了
linux7.4安装python3.8.3_第4张图片

你可能感兴趣的:(Linux,Python,python,linux)