Import pylab fails from c-code

Hello everyone,

I use the following C-Code in visual
studio 2005 (I start the program with “Release” configuration):

#include <Python.h>

#include

using namespace
std;

void main()

{

    Py_Initialize();

   

    while

(1)

    {

char
test[100] = {};

cout<<">>>
";

cin.getline(test, 100);

PyRun_SimpleString(test);

    }

    Py_Finalize();

}

for my first tries to embed python in
C.

However if I try to import pylab (from
pylab import *) I get the following error:

from pylab import *

Traceback (most recent call last):

File “”,
line 1, in

File “C:\Python26\lib\site-packages\pylab.py”,
line 1, in

from matplotlib.pylab

import *

File “C:\Python26\lib\site-packages\matplotlib\pylab.py”,
line 206, in

from matplotlib import

mpl # pulls in most modules

File “C:\Python26\lib\site-packages\matplotlib\mpl.py”,
line 1, in

from matplotlib import

artist

File “C:\Python26\lib\site-packages\matplotlib\artist.py”,
line 5, in

from transforms import

Bbox, IdentityTransform, TransformedBbox, TransformedPath

File “C:\Python26\lib\site-packages\matplotlib\transforms.py”,
line 34, in

from matplotlib._path

import affine_transform

ImportError: DLL load failed: Eine DLL-Initialisierungsroutine
ist fehlgeschlagen.

and a separate error message appears
(see attached file).

Any ideas?

Markus

pylab_error.JPG

What version of matplotlib are you using? There were some linker
problems with 0.98.x similar to the ones you are showing with
python2.6, but these should be solved with 0.99.x. Also, I wouldn't
recommend importing pylab or pyplot if you are going to try embedding
mpl in C. You should use the API -- what you are trying is difficult
enough w/o dealing with some of the pylab magic like runtime backend
detection.

See

http://matplotlib.sourceforge.net/faq/howto_faq.html#matplotlib-in-a-web-application-server
http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend
http://matplotlib.sourceforge.net/faq/usage_faq.html#matplotlib-pylab-and-pyplot-how-are-they-related
http://matplotlib.sourceforge.net/users/artists.html

···

On Mon, Nov 16, 2009 at 6:16 AM, <markus.proeller@...2861...> wrote:

Hello everyone,

I use the following C-Code in visual studio 2005 (I start the program with
"Release" configuration):

#include <Python.h>
#include <iostream>
using namespace std;

void main()
{
Py_Initialize();

    while \(1\)
    \{
            char test\[100\] = \{\};
            cout&lt;&lt;&quot;&gt;&gt;&gt; &quot;;
            cin\.getline\(test, 100\);
            PyRun\_SimpleString\(test\);

    \}

    Py\_Finalize\(\);

}

for my first tries to embed python in C.
However if I try to import pylab (from pylab import *) I get the following
error:

from pylab import *

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python26\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python26\lib\site-packages\matplotlib\pylab.py", line 206, in
<module>
from matplotlib import mpl # pulls in most modules
File "C:\Python26\lib\site-packages\matplotlib\mpl.py", line 1, in
<module>
from matplotlib import artist
File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 5, in
<module>
from transforms import Bbox, IdentityTransform, TransformedBbox,
TransformedPath
File "C:\Python26\lib\site-packages\matplotlib\transforms.py", line 34, in
<module>
from matplotlib._path import affine_transform
ImportError: DLL load failed: Eine DLL-Initialisierungsroutine ist
fehlgeschlagen.

Hello everyone,

I use the following C-Code in visual studio 2005 (I start the
program with

“Release” configuration):

#include <Python.h>

#include

using namespace std;

void main()

{

    Py_Initialize();
    while (1)
    {
            char

test[100] = {};

            cout<<">>>

";

            cin.getline(test,

100);

            PyRun_SimpleString(test);
    }
    Py_Finalize();

}

for my first tries to embed python in C.

However if I try to import pylab (from pylab import *) I get
the following

error:

from pylab import *

Traceback (most recent call last):

File “”, line 1, in

File “C:\Python26\lib\site-packages\pylab.py”,
line 1, in

from matplotlib.pylab import *

File “C:\Python26\lib\site-packages\matplotlib\pylab.py”,
line 206, in

from matplotlib import mpl  # pulls in most

modules

File “C:\Python26\lib\site-packages\matplotlib\mpl.py”,
line 1, in

from matplotlib import artist

File “C:\Python26\lib\site-packages\matplotlib\artist.py”,
line 5, in

from transforms import Bbox, IdentityTransform,

TransformedBbox,

TransformedPath

File “C:\Python26\lib\site-packages\matplotlib\transforms.py”,
line 34, in

from matplotlib._path import affine_transform

ImportError: DLL load failed: Eine DLL-Initialisierungsroutine
ist

fehlgeschlagen.

What version of matplotlib are you using? There were some linker

problems with 0.98.x similar to the ones you are showing with

python2.6, but these should be solved with 0.99.x. Also, I wouldn’t

recommend importing pylab or pyplot if you are going to try embedding

mpl in C. You should use the API – what you are trying is difficult

enough w/o dealing with some of the pylab magic like runtime backend

detection.

`

I have version 0.99.1 of matplotlib.

With Windows XP and Python 2.6.2

My first thought was also that there might be a linker problem.

`

`

···

`John Hunter <jdh2358@…287…> schrieb am 16.11.2009 15:14:31:

On Mon, Nov 16, 2009 at 6:16 AM, <markus.proeller@…2861…> wrote: