6

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

3

Try using the following:

import py_compile
py_compile.compile('path/to/my_functions.py')
6
  • 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 nope
    – user80602
    Jan 23, 2017 at 14:37
  • 1
    @Arindam - Hmm, perhaps this post might help: Re-import custom functions without restarting QGIS
    – Joseph
    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
    Jan 26, 2017 at 4:31
  • 1
    Thanks 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
    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
    Jan 27, 2017 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.