英文:
Install Python driver only by copying directories & files?
问题
可以通过将适当的目录和文件复制到Python中来添加驱动程序吗(在树莓派上)?我找到的所有信息都使用脚本或pip来安装,但这些方法都会出现错误,比如找不到上层模块或根本不起作用。
该驱动程序用于Waveshare 2英寸OLED(https://www.waveshare.com/wiki/2inch_LCD_Module)。
安装过程中会安装(使用适当的方法)wiringPi、RPi.GPIO和spidev,所以我认为它们是OK的。
然而,实际的OLED驱动程序文件(C和py目录)安装在/home/andy/bcm2835-1.71/WiringPi/LCD_Module_RPI_code/RaspberryPi/python/lib目录下,然后需要重新编译C文件。
如果从其目录运行,py示例可以工作,但需要将哪些目录和文件复制到实际的python3.9树中,以便它们对新项目可见,并在正确(新?)的子目录中可用,而不仅仅是随意放在可以工作的地方?
更新:
可以通过添加路径使项目正常工作,但似乎是一个混乱的方法。
import sys
sys.path.append("..")
sys.path.append("/home/andy/bcm2835-1.71/WiringPi/LCD_Module_RPI_code/RaspberryPi/python/")
from lib import LCD_2inch
已尝试多种安装方法,包括pip安装和使用路径名称。
英文:
Can a driver be added to Python just by copying the appropriate directory and files (on a Raspberry Pi)? All the info I found uses a script or pip to install but those end in an error such as upper module unknown or just don't work.
The driver is for the Waveshare 2 inch OLED (https://www.waveshare.com/wiki/2inch_LCD_Module).
The installation procedure installs (using proper methods) wiringPi, RPi.GPIO, and spidev so I expect those are OK.
The actual OLED driver files (C and py dirs) however are installed under /home/andy/bcm2835-1.71/WiringPi/LCD_Module_RPI_code/RaspberryPi/python/lib and the C is then recompiled.
The py examples work if run from their directories but which directories & files need to be copied into the actual python3.9 tree so they're known and available to new projects, in the right (new?) sub-dirs and not just dumped in where they happen to work?
update:
The project can be made to work by adding the path but it seems like a messy hack.
sys.path.append("..")
sys.path.append("/home/andy/bcm2835-1.71/WiringPi/LCD_Module_RPI_code/RaspberryPi/python/")
# import LCD_2inch
from lib import LCD_2inch
Tried several installation methods, pip install and with path name.
答案1
得分: 1
最佳答案似乎来自树莓派论坛上的“ghp”。将驱动程序的lib文件夹复制到应用程序文件夹结构中,可以删除在演示代码中使用的sys.path.append,以及包括所需特定驱动程序在内的整个项目都在一起。
切勿手动复制驱动程序到python的/lib或/lib的子目录中,因为如果/当您更新Python时,它们将消失。
https://forums.raspberrypi.com/viewtopic.php?p=2083101#p2082883
英文:
Best answer seems to be from "ghp" on the raspberrypi forum. Copy the lib folder of the driver into the application folder structure, the sys.path.append used int in the demo code can be removed, and the entire project including the specific drivers required are all together.
Never manually copy drivers into the python /lib or subdirs of /lib since they will disappear if/when you update Python.
https://forums.raspberrypi.com/viewtopic.php?p=2083101#p2082883
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论