树莓派安装python坑太多

结论:没有搞定最新的python3.7,安装python3.6成功。主要未解决的坑:
1.python3.7需要依赖SSL。但OpenSSL安装了,libssl-dev也安装了,依然提示找不到ssl.h,设置configure指定目录也不行。可能如网上报告的需要在哪里手工建个lib文件夹才行,但没试通。
2.python3.7下用pip安装百度aip失败,提示无权限,但用sudo安装又出现"main"未定义"_main()"方法。该方法是手工修改,因为pip更新到18.1后出现执行错误,需要将pip3文件手工修改,安装其它通常的包没有问题,唯独安装百度aip出现这个死循环:改回原来的,则pip无法运行,修改后则aip无法安装。
3.python3.7下安装pyaudio不成功。portaudio等依赖包都已经安装,还是通不过,只能用apt安装才能通过。

没办法,只得安装python3.6.2,在不升级pip的情况下,先将基本需要用到的包安装完。
安装python3.6.2:

//下载安装包
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
//解压
tar zxvf Python-3.6.2.tgz
//创建目录
sudo mkdir /usr/local/python3.6
//配置、安装
sudo ./configure --prefix=/usr/local/python3.6
sudo make && sudo make install
//创建软链接
sudo ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
sudo ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip3

安装python可能需要安装依赖包:

sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev

不要忘了添加环境变量:

export PATH=$PATH:/usr/local/python3.6/bin

接下来安装pyaudio:

//安装依赖包
sudo apt-get portaudio.dev portaudio19-dev
//后一个可能是关键依赖包,接下来安装pyaudio就会成功
sudo pip3 install pyaudio

安装百度aip一次成功,没有出现python3.7时的问题

sudo pip3 install baidu-aip

安装numpy时遇到点问题,树莓派安装这个包时间特别长,所以依赖包一定需要先装:

//顺序安装
sudo apt-get install libblas3 libblas-dev
sudo apt-get install liblapack-dev
sudo apt-get install libatlas-base-dev
//最后安装numpy
sudo pip3 install numpy

先写到这里,再出现问题再补充。


使用USB声卡出现的问题:
设置完默认声卡后,用Python录音和播放会出现一些错误提示,但发现录音和播放都正常,错误显示比如这样:
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘defaults.bluealsa.device’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘defaults.bluealsa.device’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
connect(2) call to /tmp/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
为了不显示这些错误可以在Python代码里加上:

os.close(sys.stderr.fileno())

你可能感兴趣的:(树莓派zero,python,百度aip,numpy,pyaudio,树莓派,python安装,树莓派zero)