Error in import matplotlib.pyplot using Python/C API

Hello,

`First, thanks for this great library.`

`      My name is Filipe Saraiva, I am developing a python backend for

Cantor, the KDE mathematical software. More infos can be read in
(in portuguese and english).`

`      Currently I have a problem when I try import pyplot in Cantor. I

am using Python 2.7.5 and matplotlib 1.3.0. The error is below:`

`import matplotlib.pyplot as plt`

`Traceback (most recent call last):`

`  File "<string>", line 1, in <module>`

`        File

“/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py”, line
98, in `

`          _backend_mod, new_figure_manager, draw_if_interactive, _show

= pylab_setup()`

`        File

“/usr/lib64/python2.7/site-packages/matplotlib/backends/init.py”,
line 25, in pylab_setup`

`    globals(),locals(),[backend_name])`

`        File

“/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py”,
line 19, in `

`    _decref = ctypes.pythonapi.Py_DecRef`

`        File "/usr/lib64/python2.7/ctypes/__init__.py", line 378, in

getattr`

`    func = self.__getitem__(name)`

`        File "/usr/lib64/python2.7/ctypes/__init__.py", line 383, in

getitem`

`    func = self._FuncPtr((name_or_ordinal, self))`

`AttributeError: kde/bin/cantor: undefined symbol: Py_DecRef`

`Well, anyone have any idea about how can I fix it?`

`Thank you,`

-- Filipe Saraiva
···

http://blog.filipesaraiva.info/?tag=gsoc2013-python-backendhttp://filipesaraiva.info/

My only guess is that there is some sort of linking/build error. Perhaps
the python-qt4 library was built and linked against a different python on
your system?

Cheers!
Ben Root

···

On Mon, Sep 2, 2013 at 12:27 AM, Filipe Saraiva <mail@...1161...>wrote:

Hello,

First, thanks for this great library.

My name is Filipe Saraiva, I am developing a python backend for Cantor,
the KDE mathematical software. More infos can be read in
gsoc2013-python-backend – Filipe Saraiva's blog (in
portuguese and english).

Currently I have a problem when I try import pyplot in Cantor. I am using
Python 2.7.5 and matplotlib 1.3.0. The error is below:

import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 98,
in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show =
pylab_setup()
  File
"/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line
25, in pylab_setup
    globals(),locals(),[backend_name])
  File
"/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py",
line 19, in <module>
    _decref = ctypes.pythonapi.Py_DecRef
  File "/usr/lib64/python2.7/ctypes/__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "/usr/lib64/python2.7/ctypes/__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: kde/bin/cantor: undefined symbol: Py_DecRef

Well, anyone have any idea about how can I fix it?

Thank you,

Really I don't know. I will question it to matplotlib maintainer.

The pyplot import in python iteractive mode (python terminal) is working properly. I can run a matplotlib example using pyplot in this mode. I get the error just in Python/C API.

···

Em Ter 03 Set 2013 17:02:28 BRT, Benjamin Root escreveu:

On Mon, Sep 2, 2013 at 12:27 AM, Filipe Saraiva > <mail@...1161... <mailto:mail@…1161…>> wrote:

    Hello,

    First, thanks for this great library.

    My name is Filipe Saraiva, I am developing a python backend for
    Cantor, the KDE mathematical software. More infos can be read in
    gsoc2013-python-backend – Filipe Saraiva's blog (in
    portuguese and english).

    Currently I have a problem when I try import pyplot in Cantor. I
    am using Python 2.7.5 and matplotlib 1.3.0. The error is below:

    import matplotlib.pyplot as plt
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py",
    line 98, in <module>
        _backend_mod, new_figure_manager, draw_if_interactive, _show =
    pylab_setup()
      File
    "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py",
    line 25, in pylab_setup
        globals(),locals(),[backend_name])
      File
    "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py",
    line 19, in <module>
        _decref = ctypes.pythonapi.Py_DecRef
      File "/usr/lib64/python2.7/ctypes/__init__.py", line 378, in
    __getattr__
        func = self.__getitem__(name)
      File "/usr/lib64/python2.7/ctypes/__init__.py", line 383, in
    __getitem__
        func = self._FuncPtr((name_or_ordinal, self))
    AttributeError: kde/bin/cantor: undefined symbol: Py_DecRef

    Well, anyone have any idea about how can I fix it?

    Thank you,

My only guess is that there is some sort of linking/build error.
Perhaps the python-qt4 library was built and linked against a
different python on your system?

Cheers!
Ben Root

--
Filipe Saraiva
http://filipesaraiva.info/

It looks like it's failing inside of ctypes. How are you including Python in your application. Perhaps the ctypes module (which is a C extension module that comes in the Python standard library) is not being included or found. I'm at a bit of a loss, but this seems like more of a general "embedding python in a C application" question, which you might try asking on the Python mailing list.

Mike

···

On 09/10/2013 08:23 AM, Filipe Saraiva wrote:

Em Ter 03 Set 2013 17:02:28 BRT, Benjamin Root escreveu:

On Mon, Sep 2, 2013 at 12:27 AM, Filipe Saraiva >> <mail@...1161... <mailto:mail@…1161…>> wrote:

     Hello,

     First, thanks for this great library.

     My name is Filipe Saraiva, I am developing a python backend for
     Cantor, the KDE mathematical software. More infos can be read in
     gsoc2013-python-backend – Filipe Saraiva's blog (in
     portuguese and english).

     Currently I have a problem when I try import pyplot in Cantor. I
     am using Python 2.7.5 and matplotlib 1.3.0. The error is below:

     import matplotlib.pyplot as plt
     Traceback (most recent call last):
       File "<string>", line 1, in <module>
       File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py",
     line 98, in <module>
         _backend_mod, new_figure_manager, draw_if_interactive, _show =
     pylab_setup()
       File
     "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py",
     line 25, in pylab_setup
         globals(),locals(),[backend_name])
       File
     "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py",
     line 19, in <module>
         _decref = ctypes.pythonapi.Py_DecRef
       File "/usr/lib64/python2.7/ctypes/__init__.py", line 378, in
     __getattr__
         func = self.__getitem__(name)
       File "/usr/lib64/python2.7/ctypes/__init__.py", line 383, in
     __getitem__
         func = self._FuncPtr((name_or_ordinal, self))
     AttributeError: kde/bin/cantor: undefined symbol: Py_DecRef

     Well, anyone have any idea about how can I fix it?

     Thank you,

My only guess is that there is some sort of linking/build error.
Perhaps the python-qt4 library was built and linked against a
different python on your system?

Cheers!
Ben Root

Really I don't know. I will question it to matplotlib maintainer.

The pyplot import in python iteractive mode (python terminal) is
working properly. I can run a matplotlib example using pyplot in this
mode. I get the error just in Python/C API.

--
                    _

\/|o _|_ _. _ | | \.__ __|__|_|_ _ _ ._ _
>>(_| |(_|(/_| |_/|(_)(/_|_ |_|_)(_)(_)| | |

I am using my code with several python modules and I can not get any error. I tried scipy, numpy, Spade, matplotlib... interesting, I don't get error when I import matplotlib.animation.

You can see reports of several uses of python commands and modules in my software accessing my blog in gsoc2013-python-backend – Filipe Saraiva's blog

Interesting, I used with success pyplot in the first version of this backend, last year. The blogpost have a picture of this LaKademy results – starting development of Python backend to Cantor – Filipe Saraiva's blog.

Well, I ask to another KDE developers for test my code and verify if the pyplot error that I am getting is reproducible.

Thank you,

···

Em Ter 10 Set 2013 09:33:37 BRT, Michael Droettboom escreveu:

On 09/10/2013 08:23 AM, Filipe Saraiva wrote:

Em Ter 03 Set 2013 17:02:28 BRT, Benjamin Root escreveu:

On Mon, Sep 2, 2013 at 12:27 AM, Filipe Saraiva >>> <mail@...1161... <mailto:mail@…1161…>> wrote:

      Hello,

      First, thanks for this great library.

      My name is Filipe Saraiva, I am developing a python backend for
      Cantor, the KDE mathematical software. More infos can be read in
      gsoc2013-python-backend – Filipe Saraiva's blog (in
      portuguese and english).

      Currently I have a problem when I try import pyplot in Cantor. I
      am using Python 2.7.5 and matplotlib 1.3.0. The error is below:

      import matplotlib.pyplot as plt
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py",
      line 98, in <module>
          _backend_mod, new_figure_manager, draw_if_interactive, _show =
      pylab_setup()
        File
      "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py",
      line 25, in pylab_setup
          globals(),locals(),[backend_name])
        File
      "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py",
      line 19, in <module>
          _decref = ctypes.pythonapi.Py_DecRef
        File "/usr/lib64/python2.7/ctypes/__init__.py", line 378, in
      __getattr__
          func = self.__getitem__(name)
        File "/usr/lib64/python2.7/ctypes/__init__.py", line 383, in
      __getitem__
          func = self._FuncPtr((name_or_ordinal, self))
      AttributeError: kde/bin/cantor: undefined symbol: Py_DecRef

      Well, anyone have any idea about how can I fix it?

      Thank you,

My only guess is that there is some sort of linking/build error.
Perhaps the python-qt4 library was built and linked against a
different python on your system?

Cheers!
Ben Root

Really I don't know. I will question it to matplotlib maintainer.

The pyplot import in python iteractive mode (python terminal) is
working properly. I can run a matplotlib example using pyplot in this
mode. I get the error just in Python/C API.

It looks like it's failing inside of ctypes. How are you including
Python in your application. Perhaps the ctypes module (which is a C
extension module that comes in the Python standard library) is not being
included or found. I'm at a bit of a loss, but this seems like more of
a general "embedding python in a C application" question, which you
might try asking on the Python mailing list.

Mike

--
Filipe Saraiva
http://filipesaraiva.info/

Do any of those use ctypes? Try creating a minimal ctypes example and see if that works.

Mike

···

On 09/10/2013 10:05 AM, Filipe Saraiva wrote:

Em Ter 10 Set 2013 09:33:37 BRT, Michael Droettboom escreveu:

On 09/10/2013 08:23 AM, Filipe Saraiva wrote:

Em Ter 03 Set 2013 17:02:28 BRT, Benjamin Root escreveu:

On Mon, Sep 2, 2013 at 12:27 AM, Filipe Saraiva >>>> <mail@...1161... <mailto:mail@…1161…>> wrote:

      Hello,

      First, thanks for this great library.

      My name is Filipe Saraiva, I am developing a python backend for
      Cantor, the KDE mathematical software. More infos can be read in
gsoc2013-python-backend – Filipe Saraiva's blog (in
      portuguese and english).

      Currently I have a problem when I try import pyplot in Cantor. I
      am using Python 2.7.5 and matplotlib 1.3.0. The error is below:

      import matplotlib.pyplot as plt
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py",
      line 98, in <module>
          _backend_mod, new_figure_manager, draw_if_interactive, _show =
      pylab_setup()
        File
"/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py",
      line 25, in pylab_setup
          globals(),locals(),[backend_name])
        File
"/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py",
      line 19, in <module>
          _decref = ctypes.pythonapi.Py_DecRef
        File "/usr/lib64/python2.7/ctypes/__init__.py", line 378, in
      __getattr__
          func = self.__getitem__(name)
        File "/usr/lib64/python2.7/ctypes/__init__.py", line 383, in
      __getitem__
          func = self._FuncPtr((name_or_ordinal, self))
      AttributeError: kde/bin/cantor: undefined symbol: Py_DecRef

      Well, anyone have any idea about how can I fix it?

      Thank you,

My only guess is that there is some sort of linking/build error.
Perhaps the python-qt4 library was built and linked against a
different python on your system?

Cheers!
Ben Root

Really I don't know. I will question it to matplotlib maintainer.

The pyplot import in python iteractive mode (python terminal) is
working properly. I can run a matplotlib example using pyplot in this
mode. I get the error just in Python/C API.

It looks like it's failing inside of ctypes. How are you including
Python in your application. Perhaps the ctypes module (which is a C
extension module that comes in the Python standard library) is not being
included or found. I'm at a bit of a loss, but this seems like more of
a general "embedding python in a C application" question, which you
might try asking on the Python mailing list.

Mike

I am using my code with several python modules and I can not get any error. I tried scipy, numpy, Spade, matplotlib... interesting, I don't get error when I import matplotlib.animation.

--
                    _

\/|o _|_ _. _ | | \.__ __|__|_|_ _ _ ._ _
>>(_| |(_|(/_| |_/|(_)(/_|_ |_|_)(_)(_)| | |

Mike,

I was a bit horrified to see that ctypes import and usage in mpl; fortunately it is a workaround for a PySide bug, and should only be temporary, if it should be there at all.

Eric

···

On 2013/09/10 5:43 AM, Michael Droettboom wrote:

Do any of those use ctypes? Try creating a minimal ctypes example and
see if that works.

Don't be horrified. The Ctypes workaround went trough the mailing list, a PR with discussions including most core developers, testing, several beta/rc/final versions, and real word usage. It fixes a problem that is still present today without it: the Qt4Agg backend is practically unusable with any recent version of PySide on CPython 3.x. Anyway, the Ctypes code could be put in a try/except statement for environments that don't support Ctypes or Python's C API.

Christoph

···

On 9/10/2013 1:54 PM, Eric Firing wrote:

On 2013/09/10 5:43 AM, Michael Droettboom wrote:

Do any of those use ctypes? Try creating a minimal ctypes example and
see if that works.

Mike,

I was a bit horrified to see that ctypes import and usage in mpl;
fortunately it is a workaround for a PySide bug, and should only be
temporary, if it should be there at all.

Eric

If I understood correctly is there a problem with Qt4Agg in matplotlib 1.3?

Another KDE developer typed:

import matplotlib
from matplotlib import pyplot as plt

In my software (Cantor backend for python) and he got the error below:

Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 98, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line
25, in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py",
line 13, in
from backend_qt4 import QtCore, QtGui, FigureManagerQT, FigureCanvasQT,\
File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py",
line 25, in
from qt4_compat import QtCore, QtGui, _getSaveFileName, __version__
File "/usr/lib/python2.7/site-packages/matplotlib/backends/qt4_compat.py",
line 36, in
import sip
ImportError: /usr/lib/python2.7/site-packages/sip.so: undefined symbol:
PyExc_SystemError

One more info, I removed matplotlib 1.3 and installed matplotlib 1.2 using pip and it worked properly. I can use matplotlib in this version.

Thank you;

···

Em Ter 10 Set 2013 19:21:01 BRT, Christoph Gohlke escreveu:

On 9/10/2013 1:54 PM, Eric Firing wrote:

On 2013/09/10 5:43 AM, Michael Droettboom wrote:

Do any of those use ctypes? Try creating a minimal ctypes example and
see if that works.

Mike,

I was a bit horrified to see that ctypes import and usage in mpl;
fortunately it is a workaround for a PySide bug, and should only be
temporary, if it should be there at all.

Eric

Don't be horrified. The Ctypes workaround went trough the mailing list,
a PR with discussions including most core developers, testing, several
beta/rc/final versions, and real word usage. It fixes a problem that is
still present today without it: the Qt4Agg backend is practically
unusable with any recent version of PySide on CPython 3.x. Anyway, the
Ctypes code could be put in a try/except statement for environments that
don't support Ctypes or Python's C API.

--
Filipe Saraiva
http://filipesaraiva.info/

Do any of those use ctypes? Try creating a minimal ctypes example and
see if that works.

Mike,

I was a bit horrified to see that ctypes import and usage in mpl;
fortunately it is a workaround for a PySide bug, and should only be
temporary, if it should be there at all.

Eric

Don't be horrified. The Ctypes workaround went trough the mailing list,
a PR with discussions including most core developers, testing, several
beta/rc/final versions, and real word usage. It fixes a problem that is
still present today without it: the Qt4Agg backend is practically
unusable with any recent version of PySide on CPython 3.x. Anyway, the
Ctypes code could be put in a try/except statement for environments that
don't support Ctypes or Python's C API.

If I understood correctly is there a problem with Qt4Agg in matplotlib
1.3?

Another KDE developer typed:

import matplotlib
from matplotlib import pyplot as plt

In my software (Cantor backend for python) and he got the error below:

Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 98,
in
_backend_mod, new_figure_manager, draw_if_interactive, _show =
pylab_setup()
File
"/usr/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line
25, in pylab_setup
globals(),locals(),[backend_name])
File
"/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py",
line 13, in
from backend_qt4 import QtCore, QtGui, FigureManagerQT, FigureCanvasQT,\
File
"/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py",
line 25, in
from qt4_compat import QtCore, QtGui, _getSaveFileName, __version__
File
"/usr/lib/python2.7/site-packages/matplotlib/backends/qt4_compat.py",
line 36, in
import sip
ImportError: /usr/lib/python2.7/site-packages/sip.so: undefined symbol:
PyExc_SystemError

Again, this is a failure of a module to find a Python API symbol. In this case, it is not a matplotlib module, it is sip, part of pyqt4. It seems like some sort of linking problem.

One more info, I removed matplotlib 1.3 and installed matplotlib 1.2
using pip and it worked properly. I can use matplotlib in this version.

I'm glad you found something that works; but I don't know why it does.

Eric

···

On 2013/09/11 8:49 AM, Filipe Saraiva wrote:

Em Ter 10 Set 2013 19:21:01 BRT, Christoph Gohlke escreveu:

On 9/10/2013 1:54 PM, Eric Firing wrote:

On 2013/09/10 5:43 AM, Michael Droettboom wrote:

Thank you;

--
Filipe Saraiva
http://filipesaraiva.info/

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options