简体   繁体   English

Raspberry Pi RPi.GPIO模块用于可执行文件

[英]Raspberry pi RPi.GPIO module for executable files

I want to run a simple python program to glow LED. 我想运行一个简单的python程序来点亮LED。 I want to run as executable file on my raspberry pi. 我想在树莓派上作为可执行文件运行。 my simple test.py code is 我简单的test.py代码是

print"Welcome to LED program"
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25,GPIO.OUTPUT)
GPIO.OUTPUT(25,True)

this program runs fine if i use 如果我使用此程序运行正常

sudo python test.py

now i convert it into executable file 现在我将其转换为可执行文件

sudo pyinstaller test.py

and execute it by 并执行它

sudo ./test

output gives welcome to LED program. 输出欢迎使用LED程序。 Import error: No module name RPi.GPIO. 导入错误:没有模块名称RPi.GPIO。

I used the 1st print command to ensure that executable file conversion is correct and the program is executing correctly. 我使用第一个打印命令来确保可执行文件转换正确并且程序正确执行。

Now what happened to RPi.GPIO? 现在,RPi.GPIO发生了什么? why the module is not found in case of a executable file?? 为什么在可执行文件中找不到该模块?

Some Python scripts import modules in ways that PyInstaller cannot detect. 一些Python脚本以PyInstaller无法检测到的方式导入模块。

You can solve this with similar way to this: 您可以使用类似的方法解决此问题:

sudo pyinstaller --onefile --paths=\your-path\Lib\site-packages  .\test.py

For more detail 欲了解更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM