15AH, San Francisco

California, United States.

Send Your Mail At:

tianyingkejishe@sina.cn

Working Hours

Mon-Sat: 9.30am To 7.00pm

分类标题

Autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et dolore feugait.

分类归档 树莓派

[树莓派]自启动Python程序

树莓派启动Python脚本也是件让人头疼的事情,不符合Linux常理,简直了。

尝试一

根据以往的做法,把需要执行的程序放入/etc/rc.local文件里。使用任何需要加的程序脚本都可以,唯独Python不行,气人。

通过解析报错原因,提示无法打开Python,猜测跟权限有关,各种尝试,都无效。

尝试二

通过网上资料,说明可以通过desktop来启动程序,这话我信了,没有不信的理由了。尝试在./config目录下创建 autostart 文件夹,并在里面创建了第一个启动配置文件mystart.desktop。别说还真好使,但请注意权限问题。

[Desktop Entry]
Name=ScanTest
Comment=My Python Program
Exec=sudo python3 /home/pi/tes.py
#Icon=/home/pi/ScanTest/Scan.png
Terminal=false
MultipleArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=true

Python3异常-AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding

基于python3.6.1版本,在一个.py文件中,加入这3行:
import requests, re, sys
reload(sys)
sys.setdefaultencoding(“utf-8”)
出现这样的错误:
sys.setdefaultencoding(“utf-8”)
AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
原因分析:
Python3字符串默认编码unicode, 所以sys.setdefaultencoding也不存在了
解决:
去掉,sys.setdefaultencoding

PyQt5 AttributeError: ‘QGridLayout’ object has no attribute ‘setMargin’

PyQt4和PyQt5版本差异。

PyQt4采用:QVBoxLayout的setMargin方法

PyQt5采用:QVBoxLayout的setContentsMargins方法

 

错误提示: return QtGui.QApplication.translate(context, text, disambig)
AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QApplication’

修改:return QApplication.translate(context, text, disambig)

原因:PyQt4和PyQt5版本差异。

 

错误提示:NameError: name ‘unicode’ is not defined

修改:Python2 的unicode 函数在 Python3 中被命名为 str。在 Python3 中使用 ·str 来代替 Python2 中的 unicode.

原因:There is no such name in Python 3, no. You are trying to run Python 2 code in Python 3. In Python 3, unicode has been renamed to str.

dpkg: 处理软件包 XXXX (–configure)时出错解决方法

正在设置 ubuntu-drivers-common (1:0.4.17.7) ...
/var/lib/dpkg/info/ubuntu-drivers-common.postinst: 21: /var/lib/dpkg/info/ubuntu-drivers-common.postinst: py3compile: not found
dpkg: 处理软件包 ubuntu-drivers-common (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
正在设置 gconf2 (3.2.6-3ubuntu6) ...
/var/lib/dpkg/info/gconf2.postinst: 74: /var/lib/dpkg/info/gconf2.postinst: gconf-schemas: not found
dpkg: 处理软件包 gconf2 (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
dpkg: 依赖关系问题使得 aisleriot 的配置工作不能继续:
 aisleriot 依赖于 gconf2 (>= 2.28.1-2);然而:
  软件包 gconf2 尚未配置。
 
dpkg: 处理软件包 aisleriot (--configure)时出错:
 依赖关系问题 - 仍未被配置
dpkg: 依赖关系问题使得 software-properties-gtk 的配置工作不能继续:
 software-properties-gtk 依赖于 ubuntu-drivers-common (>= 1:0.2.75);然而:
  软件包 ubuntu-drivers-common 尚未配置。
 
dpkg: 处理软件包 software-properties-gtk (--configure)时出错:
 依赖关系问题 - 仍未被配置
dpkg: 依赖关系问题使得 apturl 的配置工作不能继续:
 apturl 依赖于 software-properties-gtk;然而:
  软件包 software-properties-gtk 尚未配置。
 
dpkg: 处理软件包 apturl (--configure)时出错:
 依赖关系问题 - 仍未被配置
因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。
                                                                    由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                        由于已经达到 MaxReports 限制,没有写入 apport 报告。
            正在设置 blueman (2.0.4-1ubuntu2) ...
/var/lib/dpkg/info/blueman.postinst: 40: /var/lib/dpkg/info/blueman.postinst: py3compile: not found
dpkg: 处理软件包 blueman (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 catfish (1.4.2-0ubuntu1) ...
/var/lib/dpkg/info/catfish.postinst: 6: /var/lib/dpkg/info/catfish.postinst: py3compile: not found
dpkg: 处理软件包 catfish (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
正在设置 python3-pyatspi (2.18.0+dfsg-3) ...
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    /var/lib/dpkg/info/python3-pyatspi.postinst: 6: /var/lib/dpkg/info/python3-pyatspi.postinst: py3compile: not found
dpkg: 处理软件包 python3-pyatspi (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 python3-speechd (0.8.3-1ubuntu3) ...
/var/lib/dpkg/info/python3-speechd.postinst: 6: /var/lib/dpkg/info/python3-speechd.postinst: py3compile: not found
dpkg: 处理软件包 python3-speechd (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 gnome-orca 的配置工作不能继续:
 gnome-orca 依赖于 python3-pyatspi (>= 2.10);然而:
  软件包 python3-pyatspi 尚未配置。
 gnome-orca 依赖于 python3-speechd (>= 0.8);然而:
  软件包 python3-speechd 尚未配置。
 
dpkg: 处理软件包 gnome-orca (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    由于已经达到 MaxReports 限制,没有写入 apport 报告。
                        dpkg: 依赖关系问题使得 gtk-theme-config 的配置工作不能继续:
 gtk-theme-config 依赖于 gconf2;然而:
  软件包 gconf2 尚未配置。
 
dpkg: 处理软件包 gtk-theme-config (--configure)时出错:
 依赖关系问题 - 仍未被配置
dpkg: 依赖关系问题使得 libgnomevfs2-common 的配置工作不能继续:
 libgnomevfs2-common 依赖于 gconf2 (>= 2.28.1-2);然而:
  软件包 gconf2 尚未配置。
 
dpkg: 处理软件包 libgnomevfs2-common (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 libgnomevfs2-0:amd64 的配置工作不能继续:
 libgnomevfs2-0:amd64 依赖于 libgnomevfs2-common (= 1:2.24.4-6.1ubuntu1);然而:
  软件包 libgnomevfs2-common 尚未配置。
 
dpkg: 处理软件包 libgnomevfs2-0:amd64 (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 libgnome2-common 的配置工作不能继续:
 libgnome2-common 依赖于 gconf2 (>= 2.28.1-2);然而:
  软件包 gconf2 尚未配置。
 
dpkg: 处理软件包 libgnome2-common (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 libgnome-2-0:amd64 的配置工作不能继续:
 libgnome-2-0:amd64 依赖于 libgnomevfs2-0 (>= 1:2.17.90);然而:
  软件包 libgnomevfs2-0:amd64 尚未配置。
 libgnome-2-0:amd64 依赖于 libgnome2-common (= 2.32.1-5ubuntu1);然而:
  软件包 libgnome2-common 尚未配置。
 
dpkg: 处理软件包 libgnome-2-0:amd64 (--configure)时出错:
 依赖关系问题 - 仍未被配置
dpkg: 依赖关系问题使得 libgnome2-bin 的配置工作不能继续:
 libgnome2-bin 依赖于 libgnome-2-0;然而:
  软件包 libgnome-2-0:amd64 尚未配置。
 
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    由于已经达到 MaxReports 限制,没有写入 apport 报告。
                        dpkg: 处理软件包 libgnome2-bin (--configure)时出错:
 依赖关系问题 - 仍未被配置
dpkg: 依赖关系问题使得 libgnome2-0:amd64 的配置工作不能继续:
 libgnome2-0:amd64 依赖于 libgnome-2-0 (= 2.32.1-5ubuntu1);然而:
  软件包 libgnome-2-0:amd64 尚未配置。
 libgnome2-0:amd64 依赖于 libgnome2-bin (= 2.32.1-5ubuntu1);然而:
  软件包 libgnome2-bin 尚未配置。
 
dpkg: 处理软件包 libgnome2-0:amd64 (--configure)时出错:
 依赖关系问题 - 仍未被配置
dpkg: 依赖关系问题使得 libbonoboui2-0:amd64 的配置工作不能继续:
 libbonoboui2-0:amd64 依赖于 libgnome2-0 (>= 2.17.3);然而:
  软件包 libgnome2-0:amd64 尚未配置。
 
dpkg: 处理软件包 libbonoboui2-0:amd64 (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    由于已经达到 MaxReports 限制,没有写入 apport 报告。
                        dpkg: 依赖关系问题使得 libgnomeui-0:amd64 的配置工作不能继续:
 libgnomeui-0:amd64 依赖于 libbonoboui2-0 (>= 2.15.1);然而:
  软件包 libbonoboui2-0:amd64 尚未配置。
 libgnomeui-0:amd64 依赖于 libgnome-2-0;然而:
  软件包 libgnome-2-0:amd64 尚未配置。
 libgnomeui-0:amd64 依赖于 libgnomevfs2-0 (>= 1:2.17.90);然而:
  软件包 libgnomevfs2-0:amd64 尚未配置。
 
dpkg: 处理软件包 libgnomeui-0:amd64 (--configure)时出错:
 依赖关系问题 - 仍未被配置
正在设置 lightdm-gtk-greeter-settings (1.2.1-0ubuntu1) ...
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    /var/lib/dpkg/info/lightdm-gtk-greeter-settings.postinst: 6: /var/lib/dpkg/info/lightdm-gtk-greeter-settings.postinst: py3compile: not found
dpkg: 处理软件包 lightdm-gtk-greeter-settings (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 python3-psutil (3.4.2-1) ...
/var/lib/dpkg/info/python3-psutil.postinst: 6: /var/lib/dpkg/info/python3-psutil.postinst: py3compile: not found
dpkg: 处理软件包 python3-psutil (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 menulibre 的配置工作不能继续:
 menulibre 依赖于 python3-psutil;然而:
  软件包 python3-psutil 尚未配置。
 
dpkg: 处理软件包 menulibre (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 mugshot (0.3.1-0ubuntu1) ...
/var/lib/dpkg/info/mugshot.postinst: 6: /var/lib/dpkg/info/mugshot.postinst: py3compile: not found
dpkg: 处理软件包 mugshot (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 nautilus-share 的配置工作不能继续:
 nautilus-share 依赖于 apturl;然而:
  软件包 apturl 尚未配置。
 
dpkg: 处理软件包 nautilus-share (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 onboard (1.2.0-0ubuntu5) ...
/var/lib/dpkg/info/onboard.postinst: 6: /var/lib/dpkg/info/onboard.postinst: py3compile: not found
dpkg: 处理软件包 onboard (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 onboard-data 的配置工作不能继续:
 onboard-data 依赖于 onboard (>= 0.99.0~alpha1~tr1507);然而:
  软件包 onboard 尚未配置。
 
dpkg: 处理软件包 onboard-data (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 python3-feedparser (5.1.3-3build1) ...
/var/lib/dpkg/info/python3-feedparser.postinst: 6: /var/lib/dpkg/info/python3-feedparser.postinst: py3compile: not found
dpkg: 处理软件包 python3-feedparser (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 python3-mako (1.0.3+ds1-1ubuntu1) ...
/var/lib/dpkg/info/python3-mako.postinst: 6: /var/lib/dpkg/info/python3-mako.postinst: py3compile: not found
dpkg: 处理软件包 python3-mako (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 rhythmbox (3.3-1ubuntu7) ...
/var/lib/dpkg/info/rhythmbox.postinst: 6: /var/lib/dpkg/info/rhythmbox.postinst: py3compile: not found
dpkg: 处理软件包 rhythmbox (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 totem-plugins (3.18.1-1ubuntu4) ...
/var/lib/dpkg/info/totem-plugins.postinst: 6: /var/lib/dpkg/info/totem-plugins.postinst: py3compile: not found
dpkg: 处理软件包 totem-plugins (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    dpkg: 依赖关系问题使得 unity-scope-openclipart 的配置工作不能继续:
 unity-scope-openclipart 依赖于 python3-feedparser;然而:
  软件包 python3-feedparser 尚未配置。
 
dpkg: 处理软件包 unity-scope-openclipart (--configure)时出错:
 依赖关系问题 - 仍未被配置
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 unity-tweak-tool (0.0.7ubuntu2) ...
/var/lib/dpkg/info/unity-tweak-tool.postinst: 6: /var/lib/dpkg/info/unity-tweak-tool.postinst: py3compile: not found
dpkg: 处理软件包 unity-tweak-tool (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 xfpanel-switch (1.0.4-0ubuntu1) ...
/var/lib/dpkg/info/xfpanel-switch.postinst: 6: /var/lib/dpkg/info/xfpanel-switch.postinst: py3compile: not found
dpkg: 处理软件包 xfpanel-switch (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                                    正在设置 ssh-import-id (5.5-0ubuntu1) ...
/var/lib/dpkg/info/ssh-import-id.postinst: 14: /var/lib/dpkg/info/ssh-import-id.postinst: py3compile: not found
dpkg: 处理软件包 ssh-import-id (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 127
由于已经达到 MaxReports 限制,没有写入 apport 报告。

 

解决方法:

sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old //现将info文件夹更名
 
sudo mkdir /var/lib/dpkg/info //再新建一个新的info文件夹
sudo apt-get update && apt-get -f install //不用解释了吧
sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old //执行完上一步操作后会在新的info文件夹下生成一些文件,现将这些文件全部移到info_old文件夹下
sudo rm -rf /var/lib/dpkg/info //把自己新建的info文件夹删掉
sudo mv /var/lib/dpkg/info_old /var/lib/dpkg/info //把以前的info文件夹重新改

 

子进程 已安装 pre-removal 脚本 返回了错误号 1或2 与 子进程 已安装 post-installation 脚本 返回了错误号 1或2

一、子进程 已安装 pre-removal 脚本 返回了错误号 1或2 解决办法:

sudo vim /var/lib/dpkg/status

找到Package: <package name>,比如Package: vsftpd

删除这部分的描述,删到下个Package: XXX前就好。存档后,再进行操作就OK了。

二、子进程 已安装 post-installation 脚本 返回了错误号 1或2 解决办法:

sudo rm /var/lib/dpkg/info/<package name>.*

比如sudo rm /var/lib/dpkg/info/vsftpd.*,存档后,再进行操作就OK了。

Python安装scrapy error: Microsoft Visual C++ 14.0 is required

3.6\twisted\words\im
copying src\twisted\words\xish\xpathparser.g -> build\lib.win-amd64-3.6\twis
ted\words\xish
running build_ext
building ‘twisted.test.raiser’ extension
error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual
C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools


 

按照提示网址打开一直提示400,算了,还是自己官网找下https://www.microsoft.com/zh-CN/download/details.aspx?id=48145

【树莓派】内外置声卡切换

树莓派是个好东西,小巧便宜的东西有很大的用处,想必这也是大家颇爱他的原因。我是个音乐爱好者,当然也是个程序员。通过DIY改造了一套HIFI智能家庭音源。可以收集自己喜欢的歌曲,通外置5.1声卡播放。感受破有耐力。你有机会也可以尝试下。

对于音乐声卡是个很重要的元素。那如何切换树莓派自身的声卡和外置高音质声卡呢,其实很简单,让我们尝试修改下。

1、首先咱们要看看树莓派总共可以识别多少声卡,你的外置声卡有没有被正确识别。

2、编辑树莓派系统默认声卡配置文件,修改card号为任何你需要修改的号,这里默认为1,正是上面USB声卡。

3、检查默认声卡配置是否正确修改。

4、找个音乐播放,体验下效果吧。