【树莓派】系统VNC修改与开机自启动脚本设置
最近在折腾树莓派,记录一下遇到的各种妙妙问题和解决法
首先是烧录,官方烧录器下载:Raspberry Pi software – Raspberry Pi,目前用的是2.0版本,我买的树莓派是4B,于是打开后选择4→64bit带桌面版
![43$YI1_N94I47886JUW)]DU](https://img2024.cnblogs.com/blog/1927811/202512/1927811-20251205095646579-2001206110.png)

之后正常下一步直到烧录完成,第一次给树莓派开机需要外接屏幕,进入到桌面上,点击左上树莓标识,选择Preferences→Control Centre→Interfaces,打开VNC滑块
![DG7[3W2CK0XXQ)KHD]1V3O0](https://img2024.cnblogs.com/blog/1927811/202512/1927811-20251205101045779-1476600258.png)
此时已经可以用real vnc viewer正常访问树莓派了,但无法传输文件,这是因为现在树莓派默认的vnc是way vnc而非vnc x11,首先启用x11服务:
systemctl enable vncserver-x11-serviced
这一步非常重要!需要确保x11可以开机自启动不然又得外接屏幕操作
然后通过:
sudo raspi-config
打开配置工具,选择Advanced Options→Wayland→x11,确认后重启树莓派即可生效,现在就可以很方便地传输文件了
另外还有一种可以从树莓派传文件给同一网段windows电脑的方法
python3 -m http.server 8000
error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. For more information visit http://rptl.io/venv note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.
懒得建虚拟环境,直接无视风险:
pip install pyarmor --break-system-packages
然而正常pip install之后却无法使用,是因为没有将其添加到环境变量,可以看到安装时就有:
WARNING: The scripts pyarmor, pyarmor-7, pyarmor-8 and pyarmor-auth are installed in '/home/【用户名】/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
需要先:
sudo nano ~/.bashrc
在最后一行加上:
export PATH="/home/【用户名】/.local/bin:$PATH"
再保存后更新:
source ~/.bashrc
/usr/bin/sudo ls
再临时恢复:
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
就可以正常打开之前出问题的文件,重新修改成正确的,现在使用pyarmor --version就能正常看到里面的内容了
顺便不推荐在树莓派上加密时设置过期时间,树莓派不联网的情况下时间容易乱
具体使用方法可以看这篇:Pyarmor9 最新加密教程:从入门到上手(参考官网文档)_pyarmor官网-CSDN博客
sudo nano /etc/systemd/system/myscript.service
其内容为:
[Unit] Description=My service After=network.target [Service] Type=simple User=【用户名】
WorkingDirectory=/home/m0yu
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/【用户名】/.Xauthority
ExecStart=/usr/bin/lxterminal --title="My Service" -e "/bin/bash -c '/usr/bin/python3 /home/【用户名】/Desktop/1.py; exec /bin/bash'"
Restart=always
RestartSec=10
TimeoutStartSec=30
[Install]
WantedBy=network.target
系统识别并启用:
sudo systemctl daemon-reload sudo systemctl enable myscript.service

浙公网安备 33010602011771号