<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[学习了解]树莓派(Raspberry PI)上的Python3.7.1，安装后用于矩阵学习及TensorF画Sin函数图，涉及到VNCServer的配置尤其是复制和开机启动相关的low安装入门]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[系统架构与硬件]]></category>
<pubDate>Sat, 15 Dec 2018 06:53:40 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	sudo useradd -m -s /bin/bash xiangdong -g irdcops&nbsp;&nbsp;#添加用户<br/><br/><textarea name="code" class="php" rows="15" cols="100">
sudo apt-get install build-essential tk-dev -y
sudo apt-get install libncurses5-dev libncursesw5-dev libreadline-dev -y
sudo apt-get install libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev -y
sudo apt-get install libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev -y
sudo apt autoremove -y
</textarea><br/><br/>DownLoad：<br/>https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz<br/>出现缺少库ModuleNotFoundError: No module named &#039;_ctypes&#039;，再次加上,关于在centos下安装python3.7.0以上版本时报错ModuleNotFoundError: No module named &#039;_ctypes&#039;的解决办法:<br/><textarea name="code" class="php" rows="15" cols="100">
3.7版本需要一个新的包libffi-devel，安装此包之后再次进行编译安装即可。

#yum install libffi-devel -y
#make install
若在安装前移除了/usr/bin下python的文件链接依赖，此时yum无法正常使用，需要自己下载相关软件包安装，为节省读者时间，放上链接

#wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libffi-devel-3.0.13-18.el7.x86_64.rpm
#rpm -ivh libffi-devel-3.0.13-18.el7.x86_64.rpm
安装完成后重新进行make install，结束后再次配置相关文件的软连接即可。
原文：https://blog.csdn.net/qq_36416904/article/details/79316972 
</textarea><br/><br/>而Raspberry Pi读取的是libffi-dev ,如下：<br/><textarea name="code" class="php" rows="15" cols="100">
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
sudo apt-get install libncursesw5-dev libgdbm-dev libc6-dev -y
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev -y
sudo apt-get install libssl-dev openssl -y
sudo apt-get install libffi-dev -y
</textarea><br/>来自：https://blog.csdn.net/wang725/article/details/79905612<br/><textarea name="code" class="php" rows="15" cols="100">
./configure --prefix=/usr/local/python37 &amp;&amp;&nbsp;&nbsp;make &amp;&amp; make install 
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1
在新版本的树莓派上出现问题：
$ python
Python 3.7.0a3 (default, Jan 10 2018, 14:36:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import ssl
Traceback (most recent call last):
&nbsp;&nbsp;File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
&nbsp;&nbsp;File &quot;/usr/local/lib/python3.7/ssl.py&quot;, line 100, in &lt;module&gt;
&nbsp;&nbsp;&nbsp;&nbsp;import _ssl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # if we can&#039;t import it, let the error propagate
ModuleNotFoundError: No module named &#039;_ssl&#039;
apt-get install libssl-dev openssl
修改python源码：
$ vi Modules/Setup
找到
# Socket module helper for socket(2)
#_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
#_ssl _ssl.c &#92;
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl &#92;
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -L$(SSL)/lib -lssl -lcrypto
改為
# Socket module helper for socket(2)
_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c &#92;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl &#92;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-L$(SSL)/lib -lssl -lcrypto
https://hk.saowen.com/a/0b0ad8c19b818139066b545032da2834cd5a1413d4dd86a3b43d715277d60309

#做软链接
#sudo cp /usr/bin/python /usr/bin/python2.7_bak #不用个性，系统自己也用python旧版本。
#sudo rm /usr/bin/python
sudo ln -s /usr/local/python37/bin/python3.7 /usr/bin/python3.7

#Pip用刚编译的最新的Pip3
#sudo mv /usr/bin/pip /usr/bin/pip2_bak&nbsp;&nbsp;#不用个性，系统自己也用python旧版本。
sudo ln -s /usr/local/python37/bin/pip3 /usr/bin/pip3.7&nbsp;&nbsp; #/usr/bin/pip3.7 -&gt; /usr/local/python37/bin/pip3

问题：pip3 install simplejson出现：
subprocess.CalledProcessError: Command ‘(‘lsb_release’, ‘-a’)’ returned non-zero exit status 1.

解决方法
find / -name lsb_release
rm -rf /usr/bin/lsb_release
于是就好了：
/usr/local/python37/bin/pip3&nbsp;&nbsp;install simplejson
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting simplejson
&nbsp;&nbsp;Downloading https://files.pythonhosted.org/packages/e3/24/c35fb1c1c315fc0fffe61ea00d3f88e85469004713dab488dee4f35b0aff/simplejson-3.16.0.tar.gz (81kB)
&nbsp;&nbsp;&nbsp;&nbsp;100% &#124;████████████████████████████████&#124; 81kB 73kB/s 
Successfully installed simplejson-3.16.0
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the &#039;pip install --upgrade pip&#039; command.
pip install --upgrade pip
root@raspberrypi:/usr/local/src/Python-3.7.1# pip install --upgrade pip 
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pip
&nbsp;&nbsp;Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
&nbsp;&nbsp;&nbsp;&nbsp;100% &#124;████████████████████████████████&#124; 1.3MB 50kB/s 
Installing collected packages: pip
&nbsp;&nbsp;Found existing installation: pip 10.0.1
&nbsp;&nbsp;&nbsp;&nbsp;Uninstalling pip-10.0.1:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Successfully uninstalled pip-10.0.1
Successfully installed pip-18.1
原文：https://blog.csdn.net/itdabaotu/article/details/83142918 

</textarea><br/>编译Python3.7.1教程：https://blog.csdn.net/RambleMY/article/details/82109788<br/><br/>安装numpy:<br/>如果成功安装好了pip，安装numpy及其他任何Python包都非常方便了<br/>　　运行pip install numpy<br/>　　pip会先自动下载与我们Python版本对应的numpy-xxx.whl文件，然后安装<br/><br/>矩阵计算：<br/><textarea name="code" class="php" rows="15" cols="100">
root@raspberrypi:/usr/local/src/Python-3.7.1# pip install numpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting numpy
&nbsp;&nbsp;Downloading https://files.pythonhosted.org/packages/2d/80/1809de155bad674b494248bcfca0e49eb4c5d8bee58f26fe7a0dd45029e2/numpy-1.15.4.zip (4.5MB)
&nbsp;&nbsp;&nbsp;&nbsp;100% &#124;████████████████████████████████&#124; 4.5MB 119kB/s 
Installing collected packages: numpy
&nbsp;&nbsp;Running setup.py install for numpy ... done
Successfully installed numpy-1.15.4

&gt;&gt;&gt; x = np.array([1.0, 2.0, 3.0])
Traceback (most recent call last):
&nbsp;&nbsp;File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
NameError: name &#039;np&#039; is not defined

&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; x = np.array([1.0, 2.0, 3.0])
&gt;&gt;&gt; print(x)
[1. 2. 3.]
&gt;&gt;&gt; type(x)
&lt;class &#039;numpy.ndarray&#039;&gt;
&gt;&gt;&gt; x = np.array([1.0, 2.0, 3.0])
&gt;&gt;&gt; y = np.array([2.0, 4.0, 6.0])
&gt;&gt;&gt; x + y
array([3., 6., 9.])
&gt;&gt;&gt; x - y
array([-1., -2., -3.])
&gt;&gt;&gt; x * y
array([ 2.,&nbsp;&nbsp;8., 18.])
&gt;&gt;&gt; print(x)
[1. 2. 3.]
&gt;&gt;&gt; print(y)
[2. 4. 6.]
&gt;&gt;&gt; print(x+y)
[3. 6. 9.]
&gt;&gt;&gt; x / 2.0
array([0.5, 1. , 1.5])
&gt;&gt;&gt; A = np.array([[1, 2], [3, 4]])&nbsp;&nbsp; 
&gt;&gt;&gt; print(A)
[[1 2]
 [3 4]]
&gt;&gt;&gt; A.shape
(2, 2)
&gt;&gt;&gt; A.dtype
dtype(&#039;int32&#039;)
&gt;&gt;&gt; B = np.array([[3, 0],[0, 6]])
&gt;&gt;&gt; A + B
array([[ 4,&nbsp;&nbsp;2],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 3, 10]])
&gt;&gt;&gt; A * B
array([[ 3,&nbsp;&nbsp;0],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ 0, 24]])
&gt;&gt;&gt; print(A)
[[1 2]
 [3 4]]
&gt;&gt;&gt; A * 10
array([[10, 20],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [30, 40]])
广播：
&gt;&gt;&gt; A = np.array([[1,2],[3,4]])
&gt;&gt;&gt; B = np.array([10,20])
&gt;&gt;&gt; A*B
array([[10, 40],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [30, 80]])

循环：
&gt;&gt;&gt; X = np.array([[51,55],[14,19],[0,4]])
&gt;&gt;&gt; for row in X:
...&nbsp;&nbsp;&nbsp;&nbsp; print(row)
... 
[51 55]
[14 19]
[0 4]

#将X转为一维数组
&gt;&gt;&gt; X = X.flatten()
&gt;&gt;&gt; print (X)
[51 55 14 19&nbsp;&nbsp;0&nbsp;&nbsp;4]

#从X里抽取大于15的元素
&gt;&gt;&gt; X &gt; 15
array([ True,&nbsp;&nbsp;True, False,&nbsp;&nbsp;True, False, False])
&gt;&gt;&gt; X[X&gt;15]
array([51, 55, 19])


</textarea><br/><br/><br/>画曲线：<br/>sudo su -<br/>pip3 install matplotlib&nbsp;&nbsp;#失败<br/>sudo apt-get install python3-matplotlib # 安装成功，但是写代码时引用失败，如下：<br/>&gt;&gt;&gt; import matplotlib.pyplot as plt<br/>Traceback (most recent call last):<br/>&nbsp;&nbsp;File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br/>ModuleNotFoundError: No module named &#039;matplotlib&#039;&nbsp;&nbsp;，成功如下：<br/><textarea name="code" class="php" rows="15" cols="100">
sudo su -&nbsp;&nbsp;#否则会[Errno 13] 权限不够
pip install&nbsp;&nbsp;matplotlib
pip install&nbsp;&nbsp;sklearn&nbsp;&nbsp; #不运行这个也能import matplotlib.pyplot as plt

import numpy as np
import matplotlib.pyplot as plt

# 生成数据
x = np.arange(0, 6, 0.1) # 以0.1为单位，生成0到6的数据
y = np.sin(x)

# 绘制图形
plt.plot(x, y)&nbsp;&nbsp;#SecureCRT不行，有博文说它将弹出一个新窗口，显示一幅如图3-16所示的曲线，但不同的是多了几个GUI按钮做修饰。
plt.show()
</textarea><br/>以上代码在树莓派的界面上运行成功输出一个新窗口的Sina曲线。<br/><br/><br/>二)VNCServer的配置尤其是复制和开机启动相关：<br/>cat /home/irdcops/shell/vncsvr/startvncsvr.sh <br/>killall Xvnc &gt;/dev/null 2&gt;&amp;1&nbsp;&nbsp;<br/>vncserver -kill :1&nbsp;&nbsp;<br/>rm -rf /tmp/.X*-lock&nbsp;&nbsp;<br/>rm -rf /tmp/.X11-unix/X*&nbsp;&nbsp;<br/>rm -rf /root/.vnc/*.log&nbsp;&nbsp;<br/>rm -rf /root/.vnc/*.pid&nbsp;&nbsp;<br/>vncserver :1 -geometry 1024x768&nbsp;&nbsp;<br/><br/>这个是手动，二是那个能从Windows里复制进去，还得要开机启动，如下配置：<br/><textarea name="code" class="php" rows="15" cols="100">
1. 安装autocutsel sudo apt-get install autocutsel
2. 打开/root/.vnc/xstartup,添加 autocutsel -fork
#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
autocutsel -fork
#x-terminal-emulator -geometry 80x24+10+10 -ls -title &quot;$VNCDESKTOP Desktop&quot; &amp;
#x-window-manager &amp;
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
3. 关闭VNC:&nbsp;&nbsp;&nbsp;&nbsp;vncserver -kill :1
4. 启动VNC:&nbsp;&nbsp;&nbsp;&nbsp;vncserver  :1

以上来自：https://www.jianshu.com/p/1cbb422cf54a
</textarea><br/><br/><br/>cat /etc/init.d/vncserver<br/><textarea name="code" class="php" rows="15" cols="100">
#!/bin/sh
### BEGIN INIT INFO
# Provides:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vncserver
# Required-Start:&nbsp;&nbsp;&nbsp;&nbsp;$local_fs
# Required-Stop:&nbsp;&nbsp;&nbsp;&nbsp; $local_fs
# Default-Start:&nbsp;&nbsp;&nbsp;&nbsp; 2 3 4 5
# Default-Stop:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 1 6
# Short-Description: Start/stop vncserver
### END INIT INFO
# 第一行是告诉系统这个脚本文件通过/bin/目录下的sh来执行
# 后面几行是一些说明信息，说明这个脚本是干嘛的
# 这脚本是用来开启和关闭vncserver的
 
# More details see:
# http://www.penguintutor.com/linux/vnc
 
### Customize this entry
# Set the USER variable to the name of the user to start vncserver under
export USER=&#039;root&#039;
### End customization required
# 导出环境变量USER=&#039;pi&#039;
 
eval cd ~$USER
# eval表示该句扫过两次，首先将cd ~$USER替换为cd ~pi
# 接着执行cd ~pi
 
# 如果sh执行这个脚本的时候传入的第一个参数是start，就...
# 如果sh执行这个脚本的时候传入的第一个参数是stop，就...
# 如果sh执行这个脚本的时候传入的第一个参数是其他，就...
case &quot;$1&quot; in
&nbsp;&nbsp;start)
&nbsp;&nbsp;&nbsp;&nbsp;# 启动命令行。此处自定义分辨率、控制台号码或其它参数。
&nbsp;&nbsp;&nbsp;&nbsp;su $USER -c &#039;/usr/bin/vncserver -depth 16 -geometry 1024x768 :1&#039;
&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Starting VNC server for $USER &quot;
&nbsp;&nbsp;&nbsp;&nbsp;;;
&nbsp;&nbsp;stop)
&nbsp;&nbsp;&nbsp;&nbsp;# 终止命令行。此处控制台号码与启动一致。
&nbsp;&nbsp;&nbsp;&nbsp;su $USER -c &#039;/usr/bin/vncserver -kill :1&#039;
&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;vncserver stopped&quot;
&nbsp;&nbsp;&nbsp;&nbsp;;;
&nbsp;&nbsp;*)
&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Usage: /etc/init.d/vncserver &#123;start&#124;stop&#125;&quot;
&nbsp;&nbsp;&nbsp;&nbsp;exit 1
&nbsp;&nbsp;&nbsp;&nbsp;;;
esac

exit 0
</textarea><br/><br/><br/>chmod 755 /etc/init.d/vncserver<br/>sudo update-rc.d vncserver defaults<br/><br/>继续解决复制问题，如下步骤：<br/>找不到：vncconfig,在红帽里找了一下，发现在：<br/>rpm -qf /usr/bin/vncconfig <br/>tigervnc-server-minimal-1.8.0-5.el7.x86_64 ，于是推测在Raspberry Pi里也是这样，指示了下：<br/>apt-get install&nbsp;&nbsp;tigervnc-standalone-server<br/>下列【新】软件包将被安装：<br/>&nbsp;&nbsp;libgnutls30 libhogweed4 libnettle6 libxfont2 tigervnc-common tigervnc-standalone-server<br/>apt-get install&nbsp;&nbsp;tigervnc-standalone-server&nbsp;&nbsp; #之前安装了一个：&nbsp;&nbsp;sudo apt-get install tightvncserver<br/> root@raspberrypi:~# vncconfig<br/>vncconfig: unable to open display &quot;&quot;<br/><br/>stat /usr/bin/vncconfig<br/>最近改动：2018-12-16 19:23:52.760773550 +0800<br/><br/>据博文，在文件/root/.vnc/xstartup,加一行 vncconfig -iconic &amp;&nbsp;&nbsp;，有的说是加： vncconfig -nowin&amp;<br/><textarea name="code" class="php" rows="15" cols="100">
 cat /root/.vnc/xstartup&nbsp;&nbsp;&nbsp;&nbsp;
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
autocutsel -fork
vncconfig -iconic &amp;
#x-terminal-emulator -geometry 80x24+10+10 -ls -title &quot;$VNCDESKTOP Desktop&quot; &amp;
#x-window-manager &amp;
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
</textarea><br/><br/><br/>三）TensorFlow：https://www.raspberrypi.org/magpi/tensorflow-ai-raspberry-pi/<br/>https://yq.aliyun.com/articles/623213
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [学习了解]树莓派(Raspberry PI)上的Python3.7.1，安装后用于矩阵学习及TensorF画Sin函数图，涉及到VNCServer的配置尤其是复制和开机启动相关的low安装入门]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>