3

This question is not about a specific error---the error arrises because I'm using matplotlib's tight_layout incorrectly.

I want to know why iPython is interpreting a line of code that I have commented out--or, rather, under what circumstances this is expected to happen (i.e., I need to relaunch the kernel, or whatever).

The error seems to persist, in spite of the fact that I re-executed the relevant imports.

Code:

import forecasting_report.analyze as fcst_rprt
analysis = fcst_rprt.ForecastingReport()
analysis.analyze()
results = analysis.user_dict

Error says:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-a62e6e8717be> in <module>()
      1 analysis = fcst_rprt.ForecastingReport()
----> 2 analysis.analyze()
      3 results = analysis.user_dict

/Users/[...]/ForecastingReport/forecasting_report/analyze.py in analyze(self)  
     44         self.breakdown = help.breakdown(self.user_dict)
---> 45         #plots.plot_breakdown(self.breakdown, self.path)
     46 
     47     def write_results(self):

<Error Stack continues>

Note:

A perfectly fine answer is : "That's just not the way it works". To be sure, I haven't tried to reproduce this error at the command line, so it just may be my ignorance of the Python interpreter.

9
  • 1
    have you tried restarting the notebook Commented May 3, 2013 at 16:11
  • Yes--that seems to fix the problem. I just don't know why the import statement doesn't pick up changes to the module. Commented May 3, 2013 at 16:12
  • 1
    in the past, i've noticed that if I installed a module, it wouldn't automatically become available, a restart is needed. Commented May 3, 2013 at 16:14
  • 3
    Python will only import a module once, if you need to reload it somewhere, you can use: reload(module_name) Commented May 3, 2013 at 16:14
  • 1
    Yup, I believe python will see that the module has already been imported, and do nothing, regardless of whether the module has been modified since. Commented May 3, 2013 at 16:17

2 Answers 2

1

Python will only initialise an imported module once, further calls to import will have no effect, even if the module has been modified since being read.

To reload a module, use the builtin function reload on the already imported module object, e.g.:

import mymodule

# ...later...
reload(mymodule)
Sign up to request clarification or add additional context in comments.

Comments

1

try

%load_ext autoreload
%autoreload 2

which should work with ipython terminal, i not sure if it works in ipython notebook. You can view help through autoreload? and this post: Autoreload of modules in IPython

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.