Can't import pylab on Windows with C API

Hello all,

I am trying to plot things from C using pylab. The configuration:

Window XP 32 bits
Python-2.6.3
numpy-1.3.0
matplotlib-0.99.1.

I can easily do this on Linux, but the same code does not work on Windows. Here is a test program that tries to import pylab:

#include <stdio.h>

#include <Python.h>

int main(void)

{

    PyObject * module = NULL;

    Py_Initialize();

    module = PyImport_ImportModule("matplotlib.pylab");

    if(module == NULL || module == Py_None)

    {

        printf("no\n");

        PyErr_Print();

        PyErr_Clear();

    }

    else

    {

        printf("yes\n");

    }

    Py_Finalize();

    return 0;

}

The code above works fine with Python2.6 and Linux. However, on Windows it fails; here is the output:

no

Traceback (most recent call last):

  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: The specified module could not be found.

Has anybody tried this?

Thanks!
Nick

I'm not aware of anyone trying this, but I suspect it's related to differences in how DLL paths are searched on Windows vs. shared objects on Linux.

This sort of seems like a lower-level Python issue -- I wonder if you could find other projects that do this and see where matplotlib differs. For instance, can you import numpy this way? If not, I would bring this up on the Python users list and see if they have any advice.

Mike

Nick Hilton wrote:

···

Hello all,

I am trying to plot things from C using pylab. The configuration:

Window XP 32 bits
Python-2.6.3
numpy-1.3.0
matplotlib-0.99.1.

I can easily do this on Linux, but the same code does not work on Windows. Here is a test program that tries to import pylab:

#include <stdio.h>

#include <Python.h>

int main(void)

{

    PyObject * module = NULL;

    Py_Initialize();

    module = PyImport_ImportModule("matplotlib.pylab");

    if(module == NULL || module == Py_None)

    {

        printf("no\n");

        PyErr_Print();

        PyErr_Clear();

    }

    else

    {

        printf("yes\n");

    }

    Py_Finalize();

    return 0;

}

The code above works fine with Python2.6 and Linux. However, on Windows it fails; here is the output:

no

Traceback (most recent call last):

  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: The specified module could not be found.

Has anybody tried this?

Thanks!
Nick

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I have confirmed that this error does not occur with Matplotlib-0.99.0 and Python 2.6.

It does occur when I remove 0.99.0 and install 0.99.1.

···

--- On Mon, 10/26/09, Michael Droettboom <mdroe@...86...> wrote:

From: Michael Droettboom <mdroe@...86...>
Subject: Re: [Matplotlib-users] Can't import pylab on Windows with C API
To: "Nick Hilton" <weegreenblobbie@...9...>
Cc: matplotlib-users@lists.sourceforge.net
Date: Monday, October 26, 2009, 5:54 AM
I'm not aware of anyone trying this,
but I suspect it's related to
differences in how DLL paths are searched on Windows vs.
shared objects
on Linux.

This sort of seems like a lower-level Python issue -- I
wonder if you
could find other projects that do this and see where
matplotlib
differs. For instance, can you import numpy this
way? If not, I would
bring this up on the Python users list and see if they have
any advice.

Mike

Nick Hilton wrote:
> Hello all,
>
> I am trying to plot things from C using pylab.
The configuration:
>
> Window XP 32 bits
> Python-2.6.3
> numpy-1.3.0
> matplotlib-0.99.1.
>
> I can easily do this on Linux, but the same code does
not work on Windows. Here is a test program that tries
to import pylab:
>
> #include <stdio.h>
>
> #include <Python.h>
>
>
>
> int main(void)
>
> {
>
> PyObject * module = NULL;
>
>
>
> Py_Initialize();
>
>
>
> module =
PyImport_ImportModule("matplotlib.pylab");
>
>
>
> if(module == NULL || module ==
Py_None)
>
> {
>
> printf("no\n");
>
> PyErr_Print();
>
> PyErr_Clear();
>
> }
>
> else
>
> {
>
>
printf("yes\n");
>
> }
>
>
>
> Py_Finalize();
>
>
>
> return 0;
>
> }
>
> The code above works fine with Python2.6 and
Linux. However, on Windows it fails; here is the
output:
>
> no
>
> Traceback (most recent call last):
>
> 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: The specified module
could not be found.
>
> Has anybody tried this?
>
> Thanks!
> Nick
>
>
>
>
>
>
------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer
Conference in SF, CA
> is the only developer event you need to attend this
year. Jumpstart your
> developing skills, take BlackBerry mobile applications
to market and stay
> ahead of the curve. Join us from November 9 - 12,
2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA