文章目录
一、CentOS 7 minimal安装与使用二、安装 pip三、关于 pip 安装依赖库的问题四、安装python
一、CentOS 7 minimal安装与使用
CentOS过期处理源: https://blog.csdn.net/weixin_49369665/article/details/143248527 CentOS过期处理源: https://www.cnblogs.com/kohler21/p/18331060
执行:
cp CentOS-Base.repo CentOS-Base.repo.backup
vi CentOS-Base.repo
# 注释mirrorurl=xxx
# 将mirror全部替换为vault
[base]
name=CentOS-$releasever - Base
#vaultlist=http://vaultlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/
baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#vaultlist=http://vaultlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#vaultlist=http://vaultlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#vaultlist=http://vaultlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
CentOS 下载地址:http://mirrors.aliyun.com/centos/7/isos/x86_64/ 我安装mini版后,ifconfig、yum、iwconfig等各种命令无法使用 出现问题处理 username is not in the sudoers file. This incident will be reported.
依次处理流程:
1.
su 切成root
2.
visudo (实际是修改/etc/sudoers文件)
3.找到这一行:
"root ALL=(ALL) ALL"
4.在下面增加:
"用户名 ALL=(ALL) ALL"
5.
:wq 保存推出,OK
或者这样处理
设置网络 使用命令vi /etc/sysconfig/network-scripts/ifcfg-ens33(这里的ifcfg-ens33是我电脑里的文件名,每台电脑可能不一样,如果不知道你电脑里的是什么,先cd /etc/sysconfig/network-scripts/,再ls,就可以看到ifcfg-xxx文件) ONBOOT=yes(把no改成yes) 开机启动网卡 重启网络模块 service network restart
或者:先设置【网络适配器】->【NAT模式】:点击【编辑】->【虚拟网络编辑器】->【NAT模式】->点击【NAT设置】查看并记住网关,然后执行: vi /etc/sysconfig/network-scripts/ifcfg-ens33设置静态IP地址:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="2957622b-93c3-44cc-bfcf-7f9818481b4b"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.160.xxx" # 新增行(x取0-255)
NETMASK="255.255.255.0" # 新增行
GATEWAY="192.168.160.x" # 新增行(上面记住的网关) IPADDR数值必须在网关的范围内
DNS1="8.8.8.8" # 新增行
DNS2="8.8.8.4" # 新增行
保存退出,重启网络模块 service network restart
没有ifconfig,安装yum install net-tools,安装完后ping www.baidu.com
切换阿里云yum – 依次(备份、下载源、生成缓存) mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum makecache 或者【CentOS7 配置163 yum源】
#!/usr/bin/bash
echo -e '\033[32m======= start ==========\033[0m'
cp CentOS7-Base-163.repo /etc/yum.repos.d/
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
mv CentOS7-Base-163.repo CentOS-Base.repo
echo
echo "cp CentOS7-Base-163.repo /etc/yum.repos.d/"
echo "cd /etc/yum.repos.d/"
echo "mv CentOS-Base.repo CentOS-Base.repo.bak"
echo "mv CentOS7-Base-163.repo CentOS-Base.repo"
echo
echo -e '\033[32m======= end ==========\033[0m'
echo "yum clean al"
echo "yum makecache"
echo "yum update"
yum clean all
sleep 1
yum makecache
sleep 1
yum update
sleep 1
echo
echo
echo -e '\033[32m======= 开始安装软件 ==========\033[0m'
echo
yum -y install gcc gcc-c++ kernel-devel
yum -y install zlib-devel bzip2-devel openssl-devel
yum -y install ncurses-devel sqlite-devel readline-devel
yum -y install tk-devel gdbm-devel db4-devel libpcap-devel
yum -y install xz-devel libffi-devel vim bzip2
echo -e '\033[32m======= done! ==========\033[0m'
SSH工具连接 安装openssh-server:yum install openssh-server -y 开放22端口或者关闭防火墙(二选一) firewall-cmd --zone=public --add-port=22/tcp --permanent # 开放22端口 其中: –zone # 作用域 –add-port=80/tcp # 添加端口,格式为:端口/通讯协议 –permanent # 永久生效,没有此参数重启后失效
systemctl stop firewalld # 关闭防火墙–临时关闭 systemctl disable firewalld # 关闭防火墙–禁止开机启动
关闭SELinux: vi /etc/selinux/config 设置:SELINUX=enforcing 改为 SELINUX=disabled 重启服务:reboot 关于使用 Xshell 或者 MobaXterm(我喜欢用这个)等其它工具连接虚拟机的网络问题。【桥接模式连接虚拟机问题处理】 【NAT模式连接虚拟机问题处理】 【迁移虚拟机连接问题】。
二、安装 pip
首先需要安装epel-release拓展源 EPEL的全称叫 Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目执行如下命令: sudo yum -y install epel-release sudo yum makecache sudo yum -y install python-pippip安装需要编译的第三方包时,需要安装:【离线安装gcc】 sudo yum install swig sudo yum -y install gcc gcc-c++ kernel-devel
三、关于 pip 安装依赖库的问题
清华镜像站:https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
临时使用: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <包名>
永久修改镜像源: pip install pip -U pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
安装opencv-python 报错: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",),)': /packages/72/c2/e9cf54ae5b1102020ef895866a67cb2e1aef72f16dd1fde5b5fb1495ad9c/opencv_python-4.2.0.34-cp36-cp36m-manylinux1_x86_64.whl
解决方法:pip install <包名> -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
四、安装python
从EPEL仓库安装:最新的EPEL 7仓库提供了Python3的安装源,如果你使用CentOS7或更新的版本的系统你也可以按照下面的步骤很轻松的从EPEL仓库安装。
安装最新版本的EPEL $ sudo yum install epel-release 用yum安装python3: $ sudo yum install python3 安装第三方包: $ sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple <包名> 注意:若是上面的安装方法未安装pip和setuptools,如果你要安装这两个库可以使用下面的命令: $ curl -O https://bootstrap.pypa.io/get-pip.py $ sudo /usr/bin/python3.8 get-pip.py
报错问题: Centos7安装opencv-python缺少共享库(libSM.so.6, libXrender.so.1, libXext.so.6)的解决办法
sudo yum whatprovides libSM.so.6
sudo yum install libSM-1.2.2-2.el7.x86_64 --setopt=protected_multilib=false
sudo yum whatprovides libXrender.so.1
sudo yum install libXext-1.3.3-3.el7.x86_64 --setopt=protected_multilib=false
或者离线安装:【下载地址】
安装依赖 [使用root用户]
【1】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 libffi-devel 【2】yum install libffi-devel -y
安装命令:
【3】tar -zxvf Python-3.7.0.tgz 【4】cd Python-3.7.0 【5】./configure --prefix=/usr/local/Python3 --enable-shared --with-ssl 【6】make & make install
软连接
【7】ln -s /usr/local/python3/bin/python3 /usr/bin/python3 【8】ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 【9】cp /usr/local/python3/bin/pyinstaller /usr/bin/pyinstaller
执行python3 -V报错:python3: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory 解决方法:cp /usr/local/Python3/lib/libpython3.8.so.1.0 /usr/lib64/
设置pip的阿里云源
【10】pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
创建虚拟环境
【11】pip3 install pipenv 【12】ln -s /usr/local/python3/bin/pipenv /usr/bin/pipenv3 【13】pipenv3 --python 3.8
进入退出虚拟环境
【14】pipenv3 shell 【15】exit
https://www.jianshu.com/p/1f00e47298f1 https://www.cnblogs.com/carey9420/p/11983468.html 虚拟环境: https://www.cnblogs.com/reblue520/p/12489897.html
python -m pip --trusted-host pypi.tuna.tsinghua.edu.cn install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip