我想通过PC远程控制EV3,以便处理在线数据。我使用PuTTY从Windows PC访问EV3。我试图按照本教程学习rpyc: https://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/stable/rpyc.html。根据教程,在我的EV3上,我运行了一个包含以下两个内容行的python脚本
#!/bin/bash
python3 `which rpyc_classic.py`
在我的PC上,我输入python:
import rpyc
conn = rpyc.classic.connect('192.168.137.2')
输入第二行时,我在Windows终端中出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\utils\classic.py", line 68, in connect
return factory.connect(host, port, SlaveService, ipv6 = ipv6, keepalive = keepalive)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\utils\factory.py", line 90, in connect
return connect_stream(s, service, config)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\utils\factory.py", line 51, in connect_stream
return connect_channel(Channel(stream), service = service, config = config)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\utils\factory.py", line 40, in connect_channel
return Connection(service, channel, config = config)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\protocol.py", line 151, in __init__
self._init_service()
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\protocol.py", line 154, in _init_service
self._local_root.on_connect()
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\service.py", line 152, in on_connect
self._conn.builtin = self._conn.modules.__builtin__
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\service.py", line 121, in __getattr__
return self[name]
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\service.py", line 118, in __getitem__
self.__cache[name] = self.__getmodule(name)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\netref.py", line 196, in __call__
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\netref.py", line 71, in syncreq
return conn.sync_request(handler, oid, *args)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\protocol.py", line 438, in sync_request
self.serve(0.1)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\protocol.py", line 387, in serve
data = self._recv(timeout, wait_for_lock = True)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\protocol.py", line 345, in _recv
data = self._channel.recv()
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\channel.py", line 50, in recv
header = self.stream.read(self.FRAME_HEADER.size)
File "C:\Python27\lib\site-packages\rpyc-3.3.0-py2.7.egg\rpyc\core\stream.py", line 195, in read
raise EOFError("connection closed by peer")
EOFError: connection closed by peer
以及PuTTY终端:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 172, in _authenticate_and_serve_client
self._serve_client(sock2, credentials)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 197, in _serve_client
conn._init_service()
File "/usr/lib/python3/dist-packages/rpyc/core/protocol.py", line 154, in _init_service
self._local_root.on_connect()
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 150, in on_connect
self._conn.builtin = self._conn.modules.builtins
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 121, in __getattr__
return self[name]
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 118, in __getitem__
self.__cache[name] = self.__getmodule(name)
TypeError: 'b'instancemethod'' object is not callable
我在这里(https://github.com/tomerfiliba/rpyc/issues/250)和许多其他站点上发现,我无法将python2和python3混合用于rpyc。当我在PuTTY终端中键入 python 时,它将打开python2.7.13,因此我也在PC上安装了python2.7.13。但是,rpyc教程(上面的代码)要我用python3打开rpyc-server。另外,上面的完整错误消息看起来像python 3已经用于rpyc服务器。我需要更改任何python版本吗?我怎么做?先感谢您!
我还尝试使用
启动python服务器。python `which rpyc_classic.py`
而不是“ python3 ...”,则没有发生该错误,但是在本教程的下一步中:
ev3 = conn.modules['ev3dev.ev3']
我得到了错误:
ImportError: No module named ev3dev.ev3
这显然引起了,因为ev3dev-lang-python再次需要python3。我很困惑,何时使用哪个python版本。你能帮我吗?