AttributeError: 'serial' モジュールに 'to_bytes' 属性がありません。

AttributeError: 'serial' モジュールに 'to_bytes' 属性がありません。

Pythonを使ってArduino Unoをプログラムしようとしています。私のPythonバージョンはPython 3.8です。 pyfirmata2を正常にインストールしました。しかし、コマンドラインからpyfirmata2をインポートしようとすると、次のエラーが発生します。

>>> import pyfirmata2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python38\lib\site-packages\pyfirmata2\__init__.py", line 2, in <module>
    from .pyfirmata2 import *  # NOQA
  File "C:\Python38\lib\site-packages\pyfirmata2\pyfirmata2.py", line 7, in <module>
    import serial.tools.list_ports
  File "C:\Python38\lib\site-packages\serial\tools\list_ports.py", line 27, in <module>
    from serial.tools.list_ports_windows import *
  File "C:\Python38\lib\site-packages\serial\tools\list_ports_windows.py", line 127, in <module>
    Ports = serial.to_bytes([80, 111, 114, 116, 115]) # "Ports"
AttributeError: module 'serial' has no attribute 'to_bytes'

ベストアンサー1

この方法はタイプto_bytes()で使用できますint

実行中のコードでは型ではないように見えますが、対応するserialメソッドを持たないint型です。moduleto_bytes()

どのバージョンを実行しているかは明らかではありませんが、その行がpyserial見つかりません。Ports = serial.to_bytes([80, 111, 114, 116, 115]) # "Ports"このファイルの現在のソースコードは、以下で提供されます。pyserial。 2016年にこの行が削除されたことがわかりました。今回の出品ででは、その場合は、最新バージョンでpyserial問題を解決できますか?

おすすめ記事