Orangepi 香橙派 安装 Debian 系统 并且 安装 wxpy (微信机器人) 入坑记录

硬件准备:Orangepi-PC 香橙派 (早期的型号,1G RAM ,资源还是很丰富的)

软件准备:Debian_jessie_mini.img (来自官网的系统),SecureCRT

一、安装Debian

刚买下Orangepi的时候,我安装的是Kali,但是感觉这个系统附带的软件太多了,有些臃肿。后来玩了一阵子ArchLinux,感觉还可以,但是附带的软件也太少了,连GCC也没有,简直就是两个极端。前段时间看到 wxpy 挺有意思的,现在微信这么火,安装QQ的人都少了,用微信做一些应用还是比较方便的,然后我就按照wxpy官方的安装流程开始操作。但是没想到,在ArchLinux上安装被坑惨了,折腾了好几天,安装wxpy以后要访问微信的web端必须使用SSL,ArchLinux自带的OpenSSL版本太低,更新以后又提示若干库文件版本不对,pacman 也不能用了。重烧系统,干脆升级整个系统,升级了184个程序,最后折腾折腾,总算是能用wxpy了,但是只要重启,系统就起不来了,回想一下,更新的时候更新了linux-firmware,估计是这个导致的,算了,不折腾了,换系统。

官方的Debian_jessie_mini.img体积也比较小,拿来试试。先用SDFormatter格式化TF卡,“选项设置”里选择“逻辑大小调整”为“开启(ON)”

然后使用Win32DiskImager写入镜像文件。写入完成后,可以看到TF卡能被windows识别的分区只有64M,里面有很多文件,只保留uImage和script.bin.OPI-PCxxxxx,如果你的Orangepi不接显示器,无所谓哪个script.bin.OPI-PCxxxxx,留一个就行,并去除.OPI-PCxxxxx,改名为script.bin。最后将TF卡插到Orangepi里,插好网线上电开机。

系统起来后,用SecureCRT远程连接Orangepi。首先,按照系统提示使用fs_resize对分区大小进行扩展,随后输入reboot重启

****************************************
WARNING: TO RESIZE FILESYSTEM RUN:
sudo fs_resize
to remove this message run:
sudo rm /usr/local/bin/fs_resize_warning
****************************************
root@OrangePI:~# fs_resize

Disk /dev/mmcblk0: 7.6 GiB, 8120172544 bytes, 15859712 sectors
/dev/mmcblk0p1       40960  172031  131072   64M  b W95 FAT32
/dev/mmcblk0p2      172032 1656832 1484801  725M 83 Linux

  Max block: 15858688
   Part end: 1656832
 Part start: 172032

WARNING: Do you want to resize "/dev/mmcblk0p2" (y/N)?  y
PARTITION RESIZED.
*********************************************
Rootfs Extended. Please REBOOT to take effect
*********************************************

root@OrangePI:~# 

接下来,我们修改一下源,改成国内源,下载速度快点。Debian官网显示中国大陆的源有两个,实际上一个是清华大学的服务器,另一个是中国科学技术大学的服务器,随便选一个。将/etc/apt/sources.list修改如下(我选择了清华的源)

deb http://ftp2.cn.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp2.cn.debian.org/debian/ jessie main contrib non-free

deb http://ftp2.cn.debian.org/debian/ jessie-updates main contrib non-free
deb-src http://ftp2.cn.debian.org/debian/ jessie-updates main contrib non-free

deb http://ftp2.cn.debian.org/debian/ jessie-backports main contrib non-free
deb-src http://ftp2.cn.debian.org/debian/ jessie-backports main contrib non-free

使用 apt-get update 更新源

root@OrangePI:~# apt-get update
Ign http://ftp2.cn.debian.org jessie InRelease    
Get:2 http://ftp2.cn.debian.org jessie-backports InRelease [166 kB]
Get:3 http://ftp2.cn.debian.org jessie Release.gpg [2,420 B]
。。。。。。             
Get:30 http://ftp2.cn.debian.org jessie-backports/contrib armhf Packages [7,980 B]           
Get:31 http://ftp2.cn.debian.org jessie-backports/non-free armhf Packages [6,692 B]          
Fetched 21.6 MB in 35s (606 kB/s)                                                            
Reading package lists... Done
root@OrangePI:~# 

这里说一下apt-get update与apt-get upgrade区别。update 是更新 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的地址,这样才能获取到最新的软件包。upgrade 是升级已安装的所有软件包,升级之后的版本就是本地地址里的。因此,在执行 upgrade 之前一定要执行 update,这样才能更新到最新的。

二、安装wxpy

好啦,我们接下来安装wxpy。先来看看有没有python。

root@OrangePI:~# python -V
Python 2.7.9
root@OrangePI:~# 

python 2.7.9 版本的,看看有没有更新的版本

root@OrangePI:~# apt-get install python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python is already the newest version.
python set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 112 not upgraded.
root@OrangePI:~# 

就这的凑合用吧,当然,可以使用 apt-get install python3 安装python3版本的。

下面,安装wxpy,根据官网建议,使用国内源

pip install -U wxpy -i "https://pypi.doubanio.com/simple/"

啊哦,提示pip命令找不到

root@OrangePI:~# pip install -U wxpy -i "https://pypi.doubanio.com/simple/"
-bash: pip: command not found
root@OrangePI:~# 

安装pip

root@OrangePI:~# apt-get install python-pip

稍等片刻,显示安装完毕,还安装了一大堆关联软件。再来安装wxpy,好了,安装完成。由于我们是使用远程终端操作Orangepi,为了可以在终端里显示登录微信的二维码,必须安装 pillow

root@OrangePI:~# pip install pillow 
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load
    ['__name__'])
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module>
    from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead
root@OrangePI:~# 

又报错了,看看是什么问题。stackoverflow.com 上的一个帖子给出了如下解释。

This problem is caused by a mismatch between your pip installation and your requests installation.

As of requests version 2.4.0 requests.compat.IncompleteRead has been removed. Older versions of pip, e.g. from July 2014, still relied on IncompleteRead. In the current version of pip, the import of IncompleteRead has been removed.

So the one to blame is either:

requests, for removing public API too quickly
Ubuntu for updating pip too slowly
You can solve this issue, by either updating pip via Ubuntu (if there is a newer version) or by installing pip aside from Ubuntu.

 好吧,先来卸载pip

apt-get remove python-pip

然后再装一次pip

easy_install pip

安装完成后,easy_install 提示pip安装到了/usr/local/bin 里,重启一下Orangepi,输入 pip -V 查看版本,可以看到,明显比直接从Debian获得的pip版本高

root@OrangePI:~# pip -V
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip-18.1-py2.7.egg/pip (python 2.7)

再来安装 pillow,还是输入 pip install pillow

root@OrangePI:~# pip install pillow
Collecting pillow
  Downloading https://files.pythonhosted.org/packages/1b/e1/1118d60e9946e4e77872b69c58bc2f28448ec02c99a2ce456cd1a272c5fd/Pillow-5.3.0.tar.gz (15.6MB)
    100% |████████████████████████████████| 15.6MB 88kB/s 
Building wheels for collected packages: pillow
。。。。。。
    The headers or library files could not be found for zlib,
    a required dependency when compiling Pillow from source.
    
    Please see the install instructions at:
       https://pillow.readthedocs.io/en/latest/installation.html
    
    
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-lD3XA3/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-Zvfmtx/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-lD3XA3/pillow/
root@OrangePI:~# 

好吧,继续填坑。The headers or library files could not be found for zlib  看来是没有找到zlib这个库,那就安装它

root@OrangePI:~# apt-get install zlib1g-dev

再试一次,pip install pillow 。嗯,这回变成 The headers or library files could not be found for jpeg 了,补齐它

root@OrangePI:~# apt-get install libjpeg-dev

继续,pip install pillow 。这次牛逼了,提示 "error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1“,WTF!!

填坑。。。

在linux中开发python时,会遇到该问题,指的是gcc未找到<Python.h>头文件,需要安装支持库。

root@OrangePI:~# apt-get install python-dev libevent-dev

看看还有坑没

root@OrangePI:~# pip install pillow                                                           
Collecting pillow
  Using cached https://files.pythonhosted.org/packages/1b/e1/1118d60e9946e4e77872b69c58bc2f28448ec02c99a2ce456cd1a272c5fd/Pillow-5.3.0.tar.gz
Building wheels for collected packages: pillow
  Running setup.py bdist_wheel for pillow ... done
  Stored in directory: /root/.cache/pip/wheels/df/81/28/47e761b5e307472ba7c2c5ced6e52037bbefe33c9c4b2a627e
Successfully built pillow
Installing collected packages: pillow
Successfully installed pillow-5.3.0
root@OrangePI:~# 

不错,终于安装成功了。下面写个简单的python试试看,就直接抄wxpy官方示例即可。

from wxpy import *
bot = Bot(console_qr=True)

# 机器人账号自身
myself = bot.self

# 向文件传输助手发送消息
bot.file_helper.send('Hello from wxpy!')

因为是使用终端操作的,需要添加参数 console_qr=True 。运行一下看看

root@OrangePI:/home/wx# python test.py 
Getting uuid of QR code.
Downloading QR code.
██████████████████████████████████████████████████████████████████████████████
██              ████  ██  ██    ████████  ████████  ██  ██████              ██
██  ██████████  ████  ████    ██████████  ██████████  ████████  ██████████  ██
██  ██      ██  ██      ██    ██    ██    ████  ████  ██    ██  ██      ██  ██
██  ██      ██  ██  ██  ████      ██  ██    ████████        ██  ██      ██  ██
██  ██      ██  ████  ██  ██    ██  ██  ██  ██    ██    ██████  ██      ██  ██
██  ██████████  ██████        ██  ██  ██████      ████  ██████  ██████████  ██
██              ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██              ██
████████████████████  ██  ██        ██████████  ██    ██    ██████████████████
████████    ██    ██      ████  ██  ████  ██████    ████████████████    ██████
████  ████    ██      ████████    ████████    ██  ██  ██            ██    ████
████    ██      ██  ██      ██    ██████████          ██        ██  ██  ██  ██
████  ██████  ██  ████    ██  ██          ██  ██  ████    ██      ████  ██  ██
██  ████████        ██    ██████    ██      ██████  ████    ██    ██████    ██
██████    ██  ██    ██        ██            ██      ██        ████  ██  ██████
████████    ██    ██  ██  ████    ████████    ██  ██  ██  ██    ██          ██
██  ████  ██  ████  ██  ██  ████████  ████  ██    ██████  ██  ████        ████
██████      ██    ██    ██      ██████  ██        ██  ████  ██    ████  ██  ██
████      ██  ████    ██████      ██████      ██      ██  ██  ██  ██████  ████
██  ██  ██  ██    ██  ██  ████    ██    ██████████  ████  ██████  ████  ██  ██
██    ██  ██████      ████        ██      ██  ████    ██████  ██████  ████████
██  ██  ██  ██  ██    ████        ██████  ██    ██  ████  ████  ██  ██████  ██
██            ██████  ████  ████    ██████          ██        ██  ████      ██
██████    ██    ████████        ██  ██  ██      ████    ██████  ████  ██    ██
██  ██  ██  ██████        ████  ██    ██        ██  ██      ██      ██    ████
██      ██  ██    ██████████  ██      ██    ██  ████      ████      ██      ██
██  ██  ██  ██████████████  ████  ██    ████    ██  ██  ████  ██████    ██████
██  ████    ██      ████  ████  ██  ██      ██    ██  ██            ██████████
██████████████████  ██      ████  ████  ████  ██████  ████  ██████        ████
██              ██    ██    ██  ████    ████████    ██████  ██  ██      ██  ██
██  ██████████  ████    ████    ████    ████  ██        ██  ██████    ██  ████
██  ██      ██  ██  ██  ██          ██  ████████    ████            ████  ████
██  ██      ██  ██  ██████  ████████  ██████  ██████        ██  ████  ████████
██  ██      ██  ████  ████████  ██    ██  ██    ██    ████  ████            ██
██  ██████████  ██████      ██████████  ██████████████  ██████  ██  ██      ██
██              ████  ████    ████    ██████    ████  ████  ██  ████  ████  ██
██████████████████████████████████████████████████████████████████████████████
Please scan the QR code to log in.

可以,哈哈,能愉快的玩微信了。

猜你喜欢

转载自blog.csdn.net/renpeng009672/article/details/83868505