Open jerrens opened 2 years ago
When the remote filesystem is mounted, it is mounted in /remote
. So the entry that needs to go in sys.path
is "/remote/lib"
.
I was able to change sys.path to:
import sys
sys.path[2] = 'lib' # Replace the default `/lib` entry with just `lib` to remove the incorrect directory separator when mounted to a Windows filesystem
instead and this fixed the problem I was having.
What impact would this have when mounting other filesystems (other than Windows NTFS)?
After the discussion on https://github.com/micropython/micropython/issues/9735 with @jimmo, my plan is to change my sys.path
to be: ['', '.frozen', 'lib', '/lib']
instead. This way, when mounting via mpremote ... mount .
(current working directory becomes /remote
), then contents of the relative lib
folder will have a higher priority than the system /lib
folder.
If the consensus is that this is a custom fix for my scenario and not anything that should be changed in MicroPython or mpremote, then this issue can be closed.
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 alib
subfolder. However, if I include\lib
tosys.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 inmpremote
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:
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 thelib
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:
main.py
mpremote connect port:COM9 mount . run main.py
from the console where the CWD is my project folder.Other details:
My project folder has the following contents: