platformio / platform-nxplpc

NXP LPC: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/nxplpc
Apache License 2.0
8 stars 12 forks source link

Every pyOCD invocation fails with ModuleNotFoundError: No module named ‘board’ #22

Closed maxgerhardt closed 3 years ago

maxgerhardt commented 3 years ago

See thread at https://community.platformio.org/t/unable-to-debug-tool-pyocd-modulenotfounderror-no-module-named-board/18111

By using a platformio.ini of

[env:lpc11u24]
platform = nxplpc
framework = mbed
board = lpc11u24

with a connected board, starting debugging in VSCode yields a

undefinedTraceback (most recent call last):
  File "pyocd-gdbserver.py", line 24, in <module>
    from pyOCD.tools.gdb_server import main
  File "site-packages\pyOCD\__init__.py", line 18, in <module>
    import board
**ModuleNotFoundError: No module named 'board'**

error. The same happens when I just try to invoke PyOCD normally as PlatformIO would

>python.exe C:\Users\Max\.platformio\packages\tool-pyocd\pyocd-gdbserver.py -t lpc11u24
Traceback (most recent call last):
  File "C:\Users\Max\.platformio\packages\tool-pyocd\pyocd-gdbserver.py", line 24, in <module>
    from pyOCD.tools.gdb_server import main
  File "C:\Users\Max\.platformio\packages\tool-pyocd\site-packages\pyOCD\__init__.py", line 18, in <module>
    import board
ModuleNotFoundError: No module named 'board'

It seems every invocation fails pyocd-gdbserver.py fails immediately with this error., not finding the board.py file / module, which exists in C:\Users\<user>\.platformio\packages\tool-pyocd\site-packages\pyOCD\board\board.py for me. Maybe the trick that the pyocd-gdbserver.py does with appending the path does not work anymore / on some configurations?

import sys
from os.path import dirname, join, normpath
from site import addsitedir

current_dir = normpath(join(dirname(__file__), "site-packages"))

addsitedir(current_dir)
sys.path.insert(0, current_dir)

from pyOCD.tools.gdb_server import main

main()

Additional info:

I also have pyOCD installed in my normal Python installation, in which PlatformIO runs. There, pyocd works normally.

pio system info
--------------------------  --------------------------------------------------------------------------
PlatformIO Core             5.0.4b1
Python                      3.8.6-final.0
System Type                 windows_amd64
Platform                    Windows-10
File System Encoding        utf-8
Locale Encoding             cp1252
PlatformIO Core Directory   C:\Users\Max\.platformio
PlatformIO Core Executable  C:\Users\Max\AppData\Local\Programs\Python\Python38\Scripts\platformio.exe
Python Executable           c:\users\max\appdata\local\programs\python\python38\python.exe
Global Libraries            0
Development Platforms       12
Tools & Toolchains          89
--------------------------  --------------------------------------------------------------------------