2

This piece of code:

from matplotlib import pyplot as plt

always worked fine until now. When i run every files with this piece of code, they are runned up to this code line and then the execution is stopped without error signaling. It works as if the file ended on that line. My matplotlib version is 1.2.0, and numpy 1.6.2. How can i solve it? Reinstalling the module?

UPDATE:

from __future__ import division
import os
import glob
import scipy
import numpy as np
import pymorph as pm
#import pylab as plb
#import math
import matplotlib
print("before matplot")
from matplotlib import pyplot as plt
print("after matplot")
import cv2
import mahotas as mh
from skimage import morphology
from math import sqrt
import copy
#... the others code's lines (1700 lines of code) are runned only if 
#"from matplotlib  import pyplot as plt" is commented

output:

>>> ================================ RESTART ================================
>>> 
before matplot

>>> ================================ RESTART ================================
>>> 

UPDATE 2:

import matplotlib.pyplot as plt; plt.figure(); plt.show()

from python Shell works and open a grey windows with command bar below

<matplotlib.figure.Figure object at 0x03741B70>
postgres
  • 2,242
  • 5
  • 34
  • 50
  • 2
    Are you sure there are no indentation issues in this line, relative to the others? Can you provide the error you get (copy/paste exactly)? If they're different, post a few. – jwarner112 Oct 22 '13 at 18:11
  • Try to undo all recent actions on the files one by one until the code works again(probably easier and faster to do with a VCS and using bisection...). As alternative post a minimal example that demonstrates the problem so that we can understand what's happening. – Bakuriu Oct 22 '13 at 18:39
  • It is not an indentation issue because i tried with another file (that i do not edited and that before correctly worked ) and have the same problem! Unfortunately i cannot undo because it happened 3 days ago and i shut down my pc. if i comment the "import" code the file it works, but without matplotlib i cannot view the images that i'm processing with my file – postgres Oct 22 '13 at 18:49
  • 1
    Is there a chance that you updated to a new version of numpy or another library that matplotlib's C portions depend on without re-compiling matplotlib? – Joe Kington Oct 22 '13 at 18:58
  • If the update was automatic.. because i have never touched libraries after installation. Which version should i have for matplotlib? – postgres Oct 22 '13 at 19:05
  • @postgres - It depends on what version of things matplotlib was compiled against. Basically, if the ABI (application binary interface) of a shared library changes, programs that are linked to that library are likely to segfault. Because matplotlib has quite a python extensions written in C, you'll see this as the python process segfaulting. `numpy` generally maintains a stable ABI, so it's unlikely (but possible) that it's due to numpy. More likely, it's due to another system library that matplotlib depends on. – Joe Kington Oct 22 '13 at 19:16
  • What exactly happens? Does the program segfault, or does `show` just not work? – Joe Kington Oct 22 '13 at 19:18
  • 1
    Can you run the import in an interactive shell? That will probably be informative. – tacaswell Oct 22 '13 at 19:25
  • What do u mean? In "output" i wrote the output got by Python Shell. – postgres Oct 22 '13 at 19:58
  • numpy version is 1.6.2, matplotlib version is 1.2.0 – postgres Oct 22 '13 at 20:05
  • I isolated the code in a new file and i think the problem could be scipy. it's possible?How can i solve? – postgres Oct 23 '13 at 00:22
  • @postgres - Scipy shouldn't directly have anything to do with it. `matplotlib` doesn't use scipy at all. What happens when you run something similar to `python -c 'import matplotlib.pyplot as plt; plt.figure(); plt.show()'` from the terminal? It's not clear from the information you've shown whether things are segfaulting or if matplotlib just doesn't have an interactive backend available. – Joe Kington Oct 23 '13 at 13:10
  • Also, the error you're getting about `scipy` is because you haven't imported `scipy.misc`. You'll need to add the line `import scipy.misc` before you can call functions in the `scipy.misc` sub-module. – Joe Kington Oct 23 '13 at 13:12
  • if i run import matplotlib.pyplot as plt; plt.figure(); plt.show() it open up the matplotlib grey window with commands bar – postgres Oct 23 '13 at 13:47
  • @postgres - Okay, matplotlib is configured correctly and working properly, then. Your problem is somewhere else... – Joe Kington Oct 23 '13 at 15:13
  • Ok, if i put: import matplotlib.pyplot as plt; plt.figure(); plt.show() after import scipy i cannot see the gray window!!! – postgres Oct 23 '13 at 17:41
  • 1
    @postgres - In that case, it sounds like your scipy installation is broken. – Joe Kington Oct 23 '13 at 19:42
  • 1
    yes i reinstalled, and now it works! Thanks! – postgres Oct 23 '13 at 23:13

1 Answers1

0

I was having the same issue. It looks like if you remove the .pyc file from the directory it works just fine. Check this answer out for more info https://stackoverflow.com/a/14132653/1373468

Community
  • 1
  • 1
Robin Newhouse
  • 2,158
  • 2
  • 19
  • 17