在linux下折腾wxpy,想着尝试给小聪子发送信息,一直失败,后来误删了pyhon特定文件,无奈,只有重投开始搞
1、yum是用python写的
2、删除pyhon
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联 whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令 whereis python ##验证删除,返回无结果
3、删除yum
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
whereis yum |xargs rm -frv
4、在/usr/local/src下创建yum和python用于存放python包
cd /usr/local/src/python wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-2.7.5-58.el7.x86_64.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/dbus-python-devel-1.1.1-9.el7.x86_64.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-libs-2.7.5-58.el7.x86_64.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/rpm-python-4.11.3-25.el7.x86_64.rpm 安装执行: rpm -ivh python-* rpm-python-* --nodeps --force
cd /usr/local/src/yum wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm 安装执行: rpm -ivh yum-*
5、centos安装pip
sudo yum -y install epel-release
sudo yum -y install python-pip
6、centos下使用pip安装wxpy
pip install wxpy
7、调用wxpy的say_hi_lady.py
#! /usr/bin/python # -*- coding: UTF-8 -*- import commands import sys import hashlib import os import json reload(sys) sys.setdefaultencoding('utf8') from wxpy import * bot = Bot() my_girl_friend = bot.friends().search('小聪子')[0] my_girl_friend.send('Hello WeChat!')
发现一直报错:
解答:FileNotFoundError为python3使用的文本不存在异常处理方法;在python2.7中使用IOError。这里需要调整