标题:[学习了解]树莓派(Raspberry PI)上的Python3.7.1,安装后用于矩阵学习及TensorF画Sin函数图,涉及到VNCServer的配置尤其是复制和开机启动相关的low安装入门 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Sat, 15 Dec 2018 14:53:40 +0000 作者:jackxiang 地址:http://jackxiang.com/post/9995/ 内容: sudo useradd -m -s /bin/bash xiangdong -g irdcops #添加用户 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 DownLoad: https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz 出现缺少库ModuleNotFoundError: No module named '_ctypes',再次加上,关于在centos下安装python3.7.0以上版本时报错ModuleNotFoundError: No module named '_ctypes'的解决办法: 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 而Raspberry Pi读取的是libffi-dev ,如下: 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 来自:https://blog.csdn.net/wang725/article/details/79905612 ./configure --prefix=/usr/local/python37 && make && 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 "help", "copyright", "credits" or "license" for more information. >>> import ssl Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/ssl.py", line 100, in import _ssl # if we can't import it, let the error propagate ModuleNotFoundError: No module named '_ssl' 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 \ # -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ # -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 \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -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 #不用个性,系统自己也用python旧版本。 sudo ln -s /usr/local/python37/bin/pip3 /usr/bin/pip3.7 #/usr/bin/pip3.7 -> /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 install simplejson Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting simplejson Downloading https://files.pythonhosted.org/packages/e3/24/c35fb1c1c315fc0fffe61ea00d3f88e85469004713dab488dee4f35b0aff/simplejson-3.16.0.tar.gz (81kB) 100% |████████████████████████████████| 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 'pip install --upgrade pip' 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 Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB) 100% |████████████████████████████████| 1.3MB 50kB/s Installing collected packages: pip Found existing installation: pip 10.0.1 Uninstalling pip-10.0.1: Successfully uninstalled pip-10.0.1 Successfully installed pip-18.1 原文:https://blog.csdn.net/itdabaotu/article/details/83142918 编译Python3.7.1教程:https://blog.csdn.net/RambleMY/article/details/82109788 安装numpy: 如果成功安装好了pip,安装numpy及其他任何Python包都非常方便了   运行pip install numpy   pip会先自动下载与我们Python版本对应的numpy-xxx.whl文件,然后安装 矩阵计算: 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 Downloading https://files.pythonhosted.org/packages/2d/80/1809de155bad674b494248bcfca0e49eb4c5d8bee58f26fe7a0dd45029e2/numpy-1.15.4.zip (4.5MB) 100% |████████████████████████████████| 4.5MB 119kB/s Installing collected packages: numpy Running setup.py install for numpy ... done Successfully installed numpy-1.15.4 >>> x = np.array([1.0, 2.0, 3.0]) Traceback (most recent call last): File "", line 1, in NameError: name 'np' is not defined >>> import numpy as np >>> x = np.array([1.0, 2.0, 3.0]) >>> print(x) [1. 2. 3.] >>> type(x) >>> x = np.array([1.0, 2.0, 3.0]) >>> y = np.array([2.0, 4.0, 6.0]) >>> x + y array([3., 6., 9.]) >>> x - y array([-1., -2., -3.]) >>> x * y array([ 2., 8., 18.]) >>> print(x) [1. 2. 3.] >>> print(y) [2. 4. 6.] >>> print(x+y) [3. 6. 9.] >>> x / 2.0 array([0.5, 1. , 1.5]) >>> A = np.array([[1, 2], [3, 4]]) >>> print(A) [[1 2] [3 4]] >>> A.shape (2, 2) >>> A.dtype dtype('int32') >>> B = np.array([[3, 0],[0, 6]]) >>> A + B array([[ 4, 2], [ 3, 10]]) >>> A * B array([[ 3, 0], [ 0, 24]]) >>> print(A) [[1 2] [3 4]] >>> A * 10 array([[10, 20], [30, 40]]) 广播: >>> A = np.array([[1,2],[3,4]]) >>> B = np.array([10,20]) >>> A*B array([[10, 40], [30, 80]]) 循环: >>> X = np.array([[51,55],[14,19],[0,4]]) >>> for row in X: ... print(row) ... [51 55] [14 19] [0 4] #将X转为一维数组 >>> X = X.flatten() >>> print (X) [51 55 14 19 0 4] #从X里抽取大于15的元素 >>> X > 15 array([ True, True, False, True, False, False]) >>> X[X>15] array([51, 55, 19]) 画曲线: sudo su - pip3 install matplotlib #失败 sudo apt-get install python3-matplotlib # 安装成功,但是写代码时引用失败,如下: >>> import matplotlib.pyplot as plt Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'matplotlib' ,成功如下: sudo su - #否则会[Errno 13] 权限不够 pip install matplotlib pip install sklearn #不运行这个也能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) #SecureCRT不行,有博文说它将弹出一个新窗口,显示一幅如图3-16所示的曲线,但不同的是多了几个GUI按钮做修饰。 plt.show() 以上代码在树莓派的界面上运行成功输出一个新窗口的Sina曲线。 二)VNCServer的配置尤其是复制和开机启动相关: cat /home/irdcops/shell/vncsvr/startvncsvr.sh killall Xvnc >/dev/null 2>&1 vncserver -kill :1 rm -rf /tmp/.X*-lock rm -rf /tmp/.X11-unix/X* rm -rf /root/.vnc/*.log rm -rf /root/.vnc/*.pid vncserver :1 -geometry 1024x768 这个是手动,二是那个能从Windows里复制进去,还得要开机启动,如下配置: 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 "$VNCDESKTOP Desktop" & #x-window-manager & # Fix to make GNOME work export XKL_XMODMAP_DISABLE=1 /etc/X11/Xsession 3. 关闭VNC: vncserver -kill :1 4. 启动VNC: vncserver  :1 以上来自:https://www.jianshu.com/p/1cbb422cf54a cat /etc/init.d/vncserver #!/bin/sh ### BEGIN INIT INFO # Provides: vncserver # Required-Start: $local_fs # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 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='root' ### End customization required # 导出环境变量USER='pi' eval cd ~$USER # eval表示该句扫过两次,首先将cd ~$USER替换为cd ~pi # 接着执行cd ~pi # 如果sh执行这个脚本的时候传入的第一个参数是start,就... # 如果sh执行这个脚本的时候传入的第一个参数是stop,就... # 如果sh执行这个脚本的时候传入的第一个参数是其他,就... case "$1" in start) # 启动命令行。此处自定义分辨率、控制台号码或其它参数。 su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1024x768 :1' echo "Starting VNC server for $USER " ;; stop) # 终止命令行。此处控制台号码与启动一致。 su $USER -c '/usr/bin/vncserver -kill :1' echo "vncserver stopped" ;; *) echo "Usage: /etc/init.d/vncserver {start|stop}" exit 1 ;; esac exit 0 chmod 755 /etc/init.d/vncserver sudo update-rc.d vncserver defaults 继续解决复制问题,如下步骤: 找不到:vncconfig,在红帽里找了一下,发现在: rpm -qf /usr/bin/vncconfig tigervnc-server-minimal-1.8.0-5.el7.x86_64 ,于是推测在Raspberry Pi里也是这样,指示了下: apt-get install tigervnc-standalone-server 下列【新】软件包将被安装: libgnutls30 libhogweed4 libnettle6 libxfont2 tigervnc-common tigervnc-standalone-server apt-get install tigervnc-standalone-server #之前安装了一个: sudo apt-get install tightvncserver root@raspberrypi:~# vncconfig vncconfig: unable to open display "" stat /usr/bin/vncconfig 最近改动:2018-12-16 19:23:52.760773550 +0800 据博文,在文件/root/.vnc/xstartup,加一行 vncconfig -iconic & ,有的说是加: vncconfig -nowin& cat /root/.vnc/xstartup #!/bin/sh xrdb $HOME/.Xresources xsetroot -solid grey autocutsel -fork vncconfig -iconic & #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #x-window-manager & # Fix to make GNOME work export XKL_XMODMAP_DISABLE=1 /etc/X11/Xsession 三)TensorFlow:https://www.raspberrypi.org/magpi/tensorflow-ai-raspberry-pi/ https://yq.aliyun.com/articles/623213 Generated by Jackxiang's Bo-blog 2.1.1 Release