Replies: 5 comments 4 replies
-
This is because the current working directory (CWD) does not contain the file you are trying to import.
The If you did If the "psr" depends only on modules in psr = __import__('/psr').psr # Assuming /psr.py exists! Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Never change the current working directory inside a program. Instead, you should use paths. import sdcard
import os
from machine import Pin, SPI
LOGS = "/log"
spi = SPI(1, sck=11, mosi=10, miso=9)
cs = Pin(3, mode=Pin.OUT)
sd = sdcard.SDCard(spi, cs)
vfs = os.VfsFat(sd)
os.mount(vfs, LOGS)
os.listdir(LOGS)
# usually imports are on the top
from psr import psr |
Beta Was this translation helpful? Give feedback.
-
I am unable to open files that way. That’s why I posted.
f = open(/log/name.ext) does not work, comes back with a ‘no entity” (IIRC). The only way I can open files on the SD card is to change the CWD to ‘/log/’ and then f=open(name.ext) works just fine.
I got my rather big and complicated ESP32 program working just fine by using doing the CWD and appending ‘/’ to sys.path, which fixes the import issue.
os.chdir(‘/log’)
sys.path.append(‘/’)
From: Andre Müller ***@***.***>
Sent: Wednesday, July 17, 2024 12:46 PM
To: micropython/micropython ***@***.***>
Cc: smhodge42 ***@***.***>; Author ***@***.***>
Subject: Re: [micropython/micropython] sdcard.py and os.chdir() smash subsequent import (Discussion #15472)
Never change the current working directory inside a program. Instead, you should use paths.
import sdcard
import os
from machine import Pin, SPI
LOGS = "/log"
spi = SPI(1, sck=11, mosi=10, miso=9)
cs = Pin(3, mode=Pin.OUT)
sd = sdcard.SDCard(spi, cs)
vfs = os.VfsFat(sd)
os.mount(vfs, LOGS)
os.listdir(LOGS)
# usually imports are on the top
from psr import psr
—
Reply to this email directly, view it on GitHub<#15472 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A2XPQKRXKYUKA4QAPNUJ63DZM3CYHAVCNFSM6AAAAABK67VLCCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAMBXG4YDSMA>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
Beta Was this translation helpful? Give feedback.
-
Oops, good point. Can't use `abspath()`.
… On Jul 18, 2024, at 1:07 PM, Robert Hammelrath ***@***.***> wrote:
There is not os.path in MicroPython.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
We seem to be going in circles here. That seems to be exactly what I did to get it working, as I posted yesterday:
os.chdir('/log/')
sys.path.append('/')
The default system path was ['', '.frozen', '/lib']. It is now ['', '.frozen', '/lib', '/']
I can open files and do imports. Issue solved as far as I am concerned.
From: shariltumin ***@***.***>
Sent: Thursday, July 18, 2024 10:56 AM
To: micropython/micropython ***@***.***>
Cc: smhodge42 ***@***.***>; Author ***@***.***>
Subject: Re: [micropython/micropython] sdcard.py and os.chdir() smash subsequent import (Discussion #15472)
I am using mpremote
import sys
sys.path = ['', '.frozen', '/', '/lib', '/remote']
should work.
The '' should take care of all module files in the current working directory.
-
Reply to this email directly, view it on GitHub<#15472 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A2XPQKVR42UJJEGNB6NK7ULZM76UHAVCNFSM6AAAAABK67VLCCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAMBYG43TIMA>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Espressif ESP32-S3 on DevKitC-1, latest version of uPython 1.23. Using the <sdcard.py> module for access to a uSD card.
The following REPL session, which is extracted from my main application, works fine:
Files get listed and the last line imports successfully from a module already on the ESP (used in the main application). However, if I use os.chdir() to change the CWD to the mount point, the files still list fine but the import does not:
Obviously, I know what the work-around is, don't chdir(). I'm posting this in case it's a bug or if someone can tell me what I'm missing here. Thanks
Beta Was this translation helpful? Give feedback.
All reactions