I have a Python script that is working fine from Processing->Toolbox->User Scripts. However, I have put some user defined functions in "my_functions.py" that I can call from "Timing_Advance.py".
The problem is, when I edit the functions in "my_functions.py" in the QGIS script editor, I have to restart QGIS for the changes to take effect. This is perhaps because, when I restart QGIS, it makes a "my_fucntions.pyc" file and keeps it in the same location. The .pyc file is not update when I edit the user defined functions in "my_functions.py".
How can I update the my_functions.pyc file after editing, without having to restart QGIS?
UPDATE 24th Jan 2017 Looks like including the following lines isn't making any difference either
import sys
sys.path.append(r'C:\Users\EDEYARI\.qgis2\processing\scripts')
import py_compile
py_compile.compile(r'C:\Users\EDEYARI\.qgis2\processing\scripts\my_functions.py')
import my_functions
If I add some dummy lines like a "print" and re-run the script, the print doesn't give the desired output, till I re-start QGIS
1 Answer 1
Try using the following:
import py_compile
py_compile.compile('path/to/my_functions.py')
-
i added the suggested lines and then I added a dummy piece of code print "hi" in my_functions.py. if the code worked then I would have seen the response in the python console, but nopeuser80602– user806022017年01月23日 14:37:05 +00:00Commented Jan 23, 2017 at 14:37
-
1@Arindam - Hmm, perhaps this post might help: Re-import custom functions without restarting QGISJoseph– Joseph2017年01月24日 12:37:39 +00:00Commented Jan 24, 2017 at 12:37
-
I must be missing something elementary. I added these lines import imp, my_functions imp.reload(my_functions) from my_functions import * but now I get the error "See log for Details"user80602– user806022017年01月26日 04:31:35 +00:00Commented Jan 26, 2017 at 4:31
-
1Thanks for the tip. I just removed "imp" and it worked like a charm. Found the answer here <stackoverflow.com/questions/1517038/python-refresh-reload>user80602– user806022017年01月27日 07:38:39 +00:00Commented Jan 27, 2017 at 7:38
-
@Arindam - Ahh well done for solving your problem! You should post it as an answer and accept it by clicking the green-faded tick :)Joseph– Joseph2017年01月27日 09:32:58 +00:00Commented Jan 27, 2017 at 9:32