Eclipse远程系统探索器与ImportError:没有名为RPi.GPIO的模块

0 投票
2 回答
2210 浏览
提问于 2025-04-18 18:52

我按照这个教程(https://sites.google.com/site/programmersnotebook/remote-development-of-python-scripts-on-raspberry-pi-with-eclipse)操作,成功地从Eclipse客户端(Windows 7)连接到了服务器(也就是树莓派)。当我运行一个简单的Python程序时,

print 'hello'

一切都正常。不过,当我运行下面的代码时,

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)

def printFunction(channel):

    print("Button 1 pressed!")

    print("Note how the bouncetime affects the button press")

GPIO.add_event_detect(23, GPIO.RISING, callback=printFunction, bouncetime=300)

while True:

    GPIO.wait_for_edge(24, GPIO.FALLING)

    print("Button 2 Pressed")

    GPIO.wait_for_edge(24, GPIO.RISING)

    print("Button 2 Released")

GPIO.cleanup()

我遇到了以下问题:

pydev debugger: starting (pid: 7744)
Traceback (most recent call last):
  File "C:\eclipse\plugins\org.python.pydev_3.7.0.201408261926\pysrc\pydevd.py", line 2086, in <module>
debugger.run(setup['file'], None, None)
  File "C:\eclipse\plugins\org.python.pydev_3.7.0.201408261926\pysrc\pydevd.py", line 1543, in run
pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Users\francis.reed\workspace\RemoteSystemsTempFiles\10.137.10.110\home\francis\raspiproj\test.py", line 1, in <module>
import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO

注意:RPi.GPIO这个库只在服务器(树莓派)上安装,而在Eclipse客户端(Windows 7)上没有。

有没有办法让这个脚本运行时,所有的导入语句都去服务器(树莓派)上找模块,而不是在Eclipse客户端(Windows 7)上找呢?

任何帮助都非常感谢!

2 个回答

0

我在跟着同样的教程,结果遇到了同样的问题。没有正确读懂教程的最后一部分。我在不同的环境中使用Eclipse,习惯按F11键来开始调试,但在这种情况下这样做是错误的,导致了ImportError。

我对原始教程的笔记:

  1. 调试并不是指按F11键来运行调试,而是要启动调试服务器,选择 Pydev->Start Debug Server,然后在树莓派的SSH控制台上运行Python脚本。其他的在调试环境中是类似的。
  2. 在树莓派上运行同样的脚本时,如果留下了命令 pydev.settrace('DebugServerAddress'),而调试服务器没有启动,那么脚本是无法独立运行的。所以在调试完成后,这行代码需要被注释掉。
  3. 与其把Eclipse的库复制到树莓派上,不如在树莓派上运行以下命令来安装pydevd

apt install python-pip

pip install pydevd

0

我把这个搞定了……我想我遇到了一些问题。首先,我在运行远程调试的时候搞错了。这链接提供了更具体的信息:http://pydev.org/manual_adv_remote_debugger.html

还有,我的主机IP地址变了,所以在pydevd.settrace()命令里用的地址不对。

要启动远程调试器,先在代码里加个断点,然后在Eclipse的远程终端窗口里运行你的脚本。

撰写回答