I am using Canopy Version: 1.4.1 (64 bit) on a Windows 7.
I have two files A.py
and B.py
. A.py
contains some modules and B.py
imports one of A.py
's modules. When I change something on A.py
and then run B.py
a new compiled A.py
(A.pyc
) should be created but this is not the case when using the canopy IDE.
However a A.py
does get compiled after restarting the kernel (Ctrl+.).
Is there a way to recompile A.py
without having to restart the kernel?
Please help me. Thanks!
This has nothing to do with Canopy per se. It is how Python works in general. Once a module is loaded, it is not reloaded/recompiled if you change it. This can be avoided with reload
as suggested in one of the other answers. There were different attempts in the past at having auto-reload mechanism but none of them were particularly robust, causing more troubles than what they solve.
The caching behaviour will happen in any Python session (Canopy, IPython frontends like the notebook, console, etc., a regular python shell, a server process, ...).
There are others ways to workaround the problem. In IPython and Canopy, you can use the !python
command to execute your code as if you were on the shell.