Import a custom Python module in a Python script inside another script in the Python console of QGIS
I'm using QGIS in Windows. I wrote some functions in a Python script (named my_script.py) that I would like to import in another Python script but each time I do that, I have this message, even if the scripts are in the same folder or if I changed the script folder paths in the QGIS preferences:
ModuleNotFoundError: No module named 'my_script'
I checked this post that proposes a solution involving modifying the console.py file of QGIS, but I cannot find this file on Windows.
1 Answer 1
If my_script.py
is saved in C:\users\You\scripts
, then in your other script do
import sys
sys.path.append("c:/users/You/scripts")
import my_script
-
Thanks soo much!! For some reason, I've already tried this trick and it didn't work but no problem this time. I probably misspelled something.Yvanou– Yvanou2025年02月03日 12:10:48 +00:00Commented Feb 3 at 12:10