`mpremote`: Mounting Windows directory with packages in a `lib` subfolder are not found
If I connect to my pico device and mount my project directory (in Windows 10), I get an ImportError: no module named '...' when trying to import a file that is inside a lib subfolder. However, if I include \lib to sys.path so that it expects the Windows directory separator, then things will work as expected.
Is there some other recommended way to do this when developing in Windows? I'm raising this as a bug report because I expected that the mount feature in mpremote would automatically accommodate this directory separator, or that MicroPython's sys package would be able to adapt. Adding \lib to the path doesn't seem like correct approach. If I were to use Thonny to upload all files to the pico, then it would be in the correct /lib folder, so when deploying the project (after development), I'll need to change this logic in the code.
I've done a little work in Python in the past, but I'm very new to MicroPython itself, so I'm hoping I'm missing something obvious.
If others do not consider this to be a bug, then I'll close and move it over to Discussions for advice if that is more appropriate.
Example:
C:\Projects\W5500-EVB-Pico\demo>mpremote connect port:COM9 mount .
Local directory . is mounted at /remote
Connected to MicroPython at COM9
Use Ctrl-] to exit this shell
>
MicroPython bdbc444 on 2022-09-27; W5500-EVB-Pico with RP2040
Type "help()" for more information.
>>> import sys
>>> sys.path
['', '.frozen', '/lib']
>>> import queue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'queue'
>>>
>>>
>>> sys.path.insert(2, '\lib')
>>> sys.path
['', '.frozen', '\\lib', '/lib']
>>> import queue
>>>
Ultimately I'm trying to create a task for VS Code (.vscode\task.json) that will mount my project directory and automatically run main.py. I thought I had things working, but realized that my changes to a file under the lib folder in my project folder (on PC) were not showing up when running. It turns out it was running an old copy of my code that I had manually uploaded (to the lib folder in the pico VFS) instead of the version in the mount point since the sys.path was looking in /lib (local) instead of \lib (mount).
My solution for now is to:
- Add the following code at the beginning of
main.py
import sys
sys.path.insert(2, '\lib') # Look in the mounted 'lib' directory first, before the local 'lib' directory
- Run the command:
mpremote connect port:COM9 mount . run main.pyfrom the console where the CWD is my project folder.
Other details:
My project folder has the following contents:
C:\Projects\W5500-EVB-Pico\demo
| .gitignore
| cli.py
| demo.code-workspace
| fileops.py
| log.txt
| main.py
| README.md
|
+---.vscode
| tasks.json
|
+---api
| testRoutes.py
|
+---html
| flag.html
|
+---lib
| | queue.py
| |
| \---phew
| dns.py
| logging.py
| ntp.py
| server.py
| template.py
| __init__.py
|
\---tests
\---RESTClient
flag.http
ESP32-S3 `mpremote` sends corrupted fs hook when mounting local directory
Port, board and/or hardware
ESP32-S3 N8R8
MicroPython version
MicroPython 6fee099ca-dirty on 2025-06-25; Generic ESP32S3 module with Octal-SPIRAM with ESP32S3
Compiled using
- IDF 5.4.1
- python 3.13.1
- gcc-15
- macOS Sequoia 15.5
mpremote is used directly from the micropython repository (but the results are same as with latest PyPI version)
Reproduction
- Have a local folder named
local - Run
mpremote mount local
Expected behaviour
Expected to mount local directory on the device and enter the REPL
Observed behaviour
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File ".../micropython/tools/mpremote/mpremote/__main__.py", line 6, in <module>
sys.exit(main.main())
~~~~~~~~~^^
File ".../micropython/tools/mpremote/mpremote/main.py", line 615, in main
handler_func(state, args)
~~~~~~~~~~~~^^^^^^^^^^^^^
File ".../micropython/tools/mpremote/mpremote/commands.py", line 521, in do_mount
state.transport.mount_local(path, unsafe_links=args.unsafe_links)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../micropython/tools/mpremote/mpremote/transport_serial.py", line 304, in mount_local
self.exec(fs_hook_code)
~~~~~~~~~^^^^^^^^^^^^^^
File ".../micropython/tools/mpremote/mpremote/transport_serial.py", line 293, in exec
raise TransportExecError(ret, ret_err.decode())
mpremote.transport.TransportExecError: Traceback (most recent call last):
File "<stdin>", line 11
SyntaxError: invalid syntax
Additional Information
After some digging I found a recent thread #17465 which helped to resolve the issue.
After changing the size of a data chunk sent at once over REPL, mounting works as expected:
for i in range(0, len(command_bytes), 32):
self.serial.write(
command_bytes[i : min(i + 32, len(command_bytes))]
)
time.sleep(0.01)
The mpremote mount command works with an earlier build I found on the internet (this one)
So I guess the real problem lies in some build flag.
Code of Conduct
Yes, I agree