CentOS默认安装的是2.7.5版本的python
[root@iZuf6e3zah39uzoj5pg1myZ ~]# python -V
Python 2.7.5
更新成阿里云yum源
cd /etc/yum.repos.d
wget http://mirrors.aliyun.com/repo/Centos-7.repo下载阿里云的资源文件
mv CentOS-Base.repo CentOS-Base.repo.bak 修改原有的源备份
mv Centos-7.repo CentOS-Base.repo 把下载的文件重命名
yum clean all
yum makecache
yum update
安装一些依赖(不安装有几率报错)
yum -y install zlib-devel bzip2-devel openssl-devel openssl-static ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel lzma gcc
yum -y groupinstall "Development tools"
下载包
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
解压
tar -zvxf Python-3.8.5.tgz
cd Python-3.8.5
安装到指定目录
./configure --prefix=/usr/local/sbin/python-3.8.5
make && make install
Looking in links: /tmp/tmpf2s9baqm
Processing /tmp/tmpf2s9baqm/setuptools-47.1.0-py3-none-any.whl
Processing /tmp/tmpf2s9baqm/pip-20.1.1-py2.py3-none-any.whl
Installing collected packages: setuptools, pip
//需要配置python和pip的软链接
WARNING: The script easy_install-3.8 is installed in ‘/usr/local/sbin/python-3.8.5/bin‘ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts pip3 and pip3.8 are installed in ‘/usr/local/sbin/python-3.8.5/bin‘ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.1.1 setuptools-47.1.0
修改软链接
[root@iZuf6e3zah39uzoj5pg1myZ bin]# which python
/usr/bin/python
rm -rf /usr/bin/python
[root@iZuf6e3zah39uzoj5pg1myZ ~]# ln -sv /usr/local/sbin/python-3.8.5/bin/python3.8 /usr/bin/python
‘/usr/bin/python’ -> ‘/usr/local/sbin/python-3.8.5/bin/python3.8’
[root@iZuf6e3zah39uzoj5pg1myZ ~]# python -V
Python 3.8.5
[root@iZuf6e3zah39uzoj5pg1myZ ~]# which pip
/usr/bin/pip
[root@iZuf6e3zah39uzoj5pg1myZ bin]# ln -s /usr/local/sbin/python-3.8.5/bin/pip3.8 /usr/bin/pip
ln: failed to create symbolic link ‘/usr/bin/pip’: File exists
[root@iZuf6e3zah39uzoj5pg1myZ bin]# rm -rf /usr/bin/pip
[root@iZuf6e3zah39uzoj5pg1myZ bin]# ln -s /usr/local/sbin/python-3.8.5/bin/pip3.8 /usr/bin/pip
[root@iZuf6e3zah39uzoj5pg1myZ bin]# pip -V
pip 20.1.1 from /usr/local/sbin/python-3.8.5/lib/python3.8/site-packages/pip (python 3.8)
安装完python导致yum命令无法执行的问题
vi /usr/bin/yum
把#! /usr/bin/python修改为#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
#! /usr/bin/python 也要修改为#! /usr/bin/python2
关于依赖安装的问题,使用批量安装的方式生成依赖清单,多了很多奇奇怪怪的东西,就直接手动使用pip安装了
另外,linux系统无法识别模块的问题通过:
# Linux下无法识别模块
import sys
sys.path.append("/root/BlackFish")
代码结构:
BlackFish
-blackfish
-common
Blog.py
-itplatform
Cnbloggs.py
Csdn.py
main.py
运行main.py
nohup python -u main.py &
-u:不通过缓存,直接打印(没有延迟)
原文:https://www.cnblogs.com/noneplus/p/13420120.html