This thread is very informative for different versions of Python:
https://stackoverflow.com/questions/140 ... porting-it
But the answers don't help for MicroPython, since neither v2 "imp" module nor v3 "importlib" module can be imported on MicroPython 1.9.4. What is the answer to the question for MicroPython?
How to check if a python module exists without importing it
How to check if a python module exists without importing it
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell
Re: How to check if a python module exists without importing it
HermannSW wrote:This thread is very informative for different versions of Python:
https://stackoverflow.com/questions/140 ... porting-it
But the answers don't help for MicroPython, since neither v2 "imp" module nor v3 "importlib" module can be imported on MicroPython 1.9.4. What is the answer to the question for MicroPython?
The answer is it doesn’t exist.
Create an issue on github to create it.
Sent from my iPhone using Tapatalk Pro
Re: How to check if a python module exists without importing it
You can use or if you want more details for a specific module then you need to import and use simialr command to get details.
For example:
Code: Select all
help("modules")
For example:
Code: Select all
import sys
help(sys)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How to check if a python module exists without importing it
@deonis help('modules') only lists those modules which are frozen as bytecode.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: How to check if a python module exists without importing it
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell
Re: How to check if a python module exists without importing it
import-ing can have side-effects.deonis wrote:You can useor if you want more details for a specific module then you need to import and use simialr command to get details.Code: Select all
help("modules")
For example:Code: Select all
import sys help(sys)
But yeah I was fundamentally wrong.
Sent from my iPhone using Tapatalk Pro
Re: How to check if a python module exists without importing it
Help(“modules”) shows: builtin, frozen string, frozen mpy.HermannSW wrote:This thread is very informative for different versions of Python:
https://stackoverflow.com/questions/140 ... porting-it
But the answers don't help for MicroPython, since neither v2 "imp" module nor v3 "importlib" module can be imported on MicroPython 1.9.4. What is the answer to the question for MicroPython?
It doesn’t show file-based .py or .mpy
Code: Select all
mp_help_add_from_map(list, &mp_builtin_module_map);
#if MICROPY_MODULE_WEAK_LINKS
mp_help_add_from_map(list, &mp_builtin_module_weak_links_map);
#endif
#if MICROPY_MODULE_FROZEN_STR
extern const char mp_frozen_str_names[];
mp_help_add_from_names(list, mp_frozen_str_names);
#endif
#if MICROPY_MODULE_FROZEN_MPY
extern const char mp_frozen_mpy_names[];
mp_help_add_from_names(list, mp_frozen_mpy_names);
#endif
Sent from my iPhone using Tapatalk Pro