简体   繁体   中英

Out of sync Python source code from Enthought Canopy Editor?

I am using the Enthought Canopy 1.0.3 Python environment in Mac OSX, also its built-in text editor.

I have detected a strange behaviour when trying to run a script from the ipython console included in the development framework. I obtain an error message that refers to a line numbering not matching to the actual one shown in the editor, but to a previous version of the source code.

For example, this is what I obtain from the ipython console:

    %run /Users/xavi/workspace/python/saliency/maps.py

(...)

    /Users/xavi/workspace/python/saliency/binarization.py in calculate_foreground_ratio(binaryMask)
      7 
      8 
----> 9 def calculate_foreground_ratio( binaryMask ):
    10     """ Compute the ratio of foreground pixels in the provided binary mask """
    11     return binaryMask.sum().astype(float) / np.size( binaryMask ).astype(float)

NameError: global name 'np' is not defined

Notice that he is pointing at an error regarding the np. definition, which is an error that should be referred to line 11, instead of line 9.

I also tried forcing a recompilation with python -m compileall .

Any idea about how to solve this synchronization problem ?

Thank you very much in advance.

The np module is not available of the globals surrounding the execution of your code. Make sure you import numpy as np into the module and it will work fine. This is not a Canopy issue but only a scope resolution problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM