Crash on import with CGI wrapped by PHP--unhappy with .matplotlib directory?

I have a PHP script which authenticates a user and I am trying to get the PHP script to wrap a Python script using matplotlib.

As
it is, the script mostly works when invoked from the command line or as
its own CGI script. When I call it from a PHP script, it doesn’t
produce output, and testing found that when I call a Python script from
a PHP script, output works before but not after “import matplotlib”: if
the PHP script calls a script of:

#!/usr/bin/python
print “Before import matplotlib.”
import matplotlib;
print “After import matplotlib.”

the first print statement succeeds but the second one fails; the server log shows a crash of:

Before import matplotlib.Traceback (most recent call last):
File “/home/jhayward/bintmp/test.py”, line 5, in

import matplotlib;

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in
rcParams = rc_params()
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params

fname = matplotlib_fname()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname
fname = os.path.join(get_configdir(), ‘matplotlibrc’)
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper

ret = func(*args, **kwargs)

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir

raise RuntimeError(“Failed to create %s/.matplotlib; consider setting
MPLCONFIGDIR to a writable directory for matplotlib configuration
data”%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting
MPLCONFIGDIR to a writable directory for matplotlib configuration data

I think this error is somewhat misleading; it persisted after I ran a “chmod -R 1777 /root/.matplotlib”.

What is the proper way to adjust things so matplotlib will be happy with its .matplotlib directory?

···


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?
++ You can now get my books from http://CJSHayward.com

Just throwing out a suggestion here: You could try putting a matplotlibrc file in the same directory as your Python script -- it will use that instead of the one in ~/.matplotlib.

Cheers,
Mike

"Jonathan Hayward, http://JonathansCorner.com" wrote:

···

I have a PHP script which authenticates a user and I am trying to get the PHP script to wrap a Python script using matplotlib.

As it is, the script mostly works when invoked from the command line or as its own CGI script. When I call it from a PHP script, it doesn't produce output, and testing found that when I call a Python script from a PHP script, output works before but not after "import matplotlib": if the PHP script calls a script of:

#!/usr/bin/python
print "Before import matplotlib."
import matplotlib;
print "After import matplotlib."

the first print statement succeeds but the second one fails; the server log shows a crash of:

Before import matplotlib.Traceback (most recent call last):
  File "/home/jhayward/bintmp/test.py", line 5, in <module>
    import matplotlib;
  File "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line 639, in <module>
    rcParams = rc_params()
  File "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line 562, in rc_params
    fname = matplotlib_fname()
  File "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line 513, in matplotlib_fname
    fname = os.path.join(get_configdir(), 'matplotlibrc')
  File "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line 207, in wrapper
    ret = func(*args, **kwargs)
  File "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line 403, in _get_configdir
    raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)
RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

I think this error is somewhat misleading; it persisted after I ran a "chmod -R 1777 /root/.matplotlib".

What is the proper way to adjust things so matplotlib will be happy with its .matplotlib directory?


– Jonathan Hayward, christos.jonathan.hayward@…287… <mailto:christos.jonathan.hayward@…287…>

** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?
++ You can now get my books from http://CJSHayward.com
------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
------------------------------------------------------------------------

_______________________________________________
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

Tried that and reran it; I’m getting substantially the same stacktrace:

File “/home/jhayward/bintmp/test.py”, line 5, in
import matplotlib;

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in
rcParams = rc_params()
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params

fname = matplotlib_fname()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname
fname = os.path.join(get_configdir(), ‘matplotlibrc’)
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper

ret = func(*args, **kwargs)

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir
raise RuntimeError(“Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data”%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

It’s /path/matplotlibrc and not /path/.matplotlibrc or anything like that?

···

On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom <mdroe@…86…> wrote:

Just throwing out a suggestion here: You could try putting a matplotlibrc file in the same directory as your Python script – it will use that instead of the one in ~/.matplotlib.

Cheers,

Mike

“Jonathan Hayward, http://JonathansCorner.com” wrote:

I have a PHP script which authenticates a user and I am trying to get the PHP script to wrap a Python script using matplotlib.

As it is, the script mostly works when invoked from the command line or as its own CGI script. When I call it from a PHP script, it doesn’t produce output, and testing found that when I call a Python script from a PHP script, output works before but not after “import matplotlib”: if the PHP script calls a script of:

#!/usr/bin/python

print “Before import matplotlib.”

import matplotlib;

print “After import matplotlib.”

the first print statement succeeds but the second one fails; the server log shows a crash of:

Before import matplotlib.Traceback (most recent call last):

File “/home/jhayward/bintmp/test.py”, line 5, in

import matplotlib;

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in

rcParams = rc_params()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params

fname = matplotlib_fname()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname

fname = os.path.join(get_configdir(), 'matplotlibrc')

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper

ret = func(*args, **kwargs)

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir

raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

I think this error is somewhat misleading; it persisted after I ran a “chmod -R 1777 /root/.matplotlib”.

What is the proper way to adjust things so matplotlib will be happy with its .matplotlib directory?

– Jonathan Hayward, christos.jonathan.hayward@…287… mailto:christos.jonathan.hayward@...287...

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?

** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com



This SF.Net email is sponsored by the Moblin Your Move Developer’s challenge

Build the coolest Linux based applications with Moblin SDK & win great prizes

Grand prize is a trip for two to an Open Source event anywhere in the world

http://moblin-contest.org/redirect.php?banner_id=100&url=/



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


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com

I found a reason for the behavior:

The script was running as user apache, but trying to open /root/.matplotlib, and /root was mode 0700. It stopped crashing on import after I made /root mode 0711.

This is somewhat surprising behavior to me; shouldn’t it be defaulting to something besides expected access to ~root?

···

On Fri, Aug 1, 2008 at 11:38 AM, Jonathan Hayward, http://JonathansCorner.com <jonathan.hayward@…789…> wrote:

Tried that and reran it; I’m getting substantially the same stacktrace:

File “/home/jhayward/bintmp/test.py”, line 5, in
import matplotlib;

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in
rcParams = rc_params()
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params

fname = matplotlib_fname()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname
fname = os.path.join(get_configdir(), ‘matplotlibrc’)
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper

ret = func(*args, **kwargs)

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir
raise RuntimeError(“Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data”%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

It’s /path/matplotlibrc and not /path/.matplotlibrc or anything like that?

On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom <mdroe@…86…> wrote:

Just throwing out a suggestion here: You could try putting a matplotlibrc file in the same directory as your Python script – it will use that instead of the one in ~/.matplotlib.

Cheers,

Mike

“Jonathan Hayward, http://JonathansCorner.com” wrote:

I have a PHP script which authenticates a user and I am trying to get the PHP script to wrap a Python script using matplotlib.

As it is, the script mostly works when invoked from the command line or as its own CGI script. When I call it from a PHP script, it doesn’t produce output, and testing found that when I call a Python script from a PHP script, output works before but not after “import matplotlib”: if the PHP script calls a script of:

#!/usr/bin/python

print “Before import matplotlib.”

import matplotlib;

print “After import matplotlib.”

the first print statement succeeds but the second one fails; the server log shows a crash of:

Before import matplotlib.Traceback (most recent call last):

File “/home/jhayward/bintmp/test.py”, line 5, in

import matplotlib;

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in

rcParams = rc_params()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params

fname = matplotlib_fname()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname

fname = os.path.join(get_configdir(), 'matplotlibrc')

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper

ret = func(*args, **kwargs)

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir

raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

I think this error is somewhat misleading; it persisted after I ran a “chmod -R 1777 /root/.matplotlib”.

What is the proper way to adjust things so matplotlib will be happy with its .matplotlib directory?

– Jonathan Hayward, christos.jonathan.hayward@…287… mailto:christos.jonathan.hayward@...287...

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?

** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com



This SF.Net email is sponsored by the Moblin Your Move Developer’s challenge

Build the coolest Linux based applications with Moblin SDK & win great prizes

Grand prize is a trip for two to an Open Source event anywhere in the world

http://moblin-contest.org/redirect.php?banner_id=100&url=/



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


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com

It's supposed to default to the current user's home directory. Perhaps "apache" doesn't have a home directory?

Cheers,
Mike

"Jonathan Hayward, http://JonathansCorner.com" wrote:

···

I found a reason for the behavior:

The script was running as user apache, but trying to open /root/.matplotlib, and /root was mode 0700. It stopped crashing on import after I made /root mode 0711.

This is somewhat surprising behavior to me; shouldn't it be defaulting to something besides expected access to ~root?

On Fri, Aug 1, 2008 at 11:38 AM, Jonathan Hayward, > http://JonathansCorner.com <jonathan.hayward@…789… > <mailto:jonathan.hayward@…789…>> wrote:

    Tried that and reran it; I'm getting substantially the same
    stacktrace:

      File "/home/jhayward/bintmp/test.py", line 5, in <module>
        import matplotlib;
      File
    "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
    639, in <module>
        rcParams = rc_params()
      File
    "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
    562, in rc_params
        fname = matplotlib_fname()
      File
    "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
    513, in matplotlib_fname
        fname = os.path.join(get_configdir(), 'matplotlibrc')
      File
    "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
    207, in wrapper
        ret = func(*args, **kwargs)
      File
    "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
    403, in _get_configdir
        raise RuntimeError("Failed to create %s/.matplotlib; consider
    setting MPLCONFIGDIR to a writable directory for matplotlib
    configuration data"%h)
    RuntimeError: Failed to create /root/.matplotlib; consider setting
    MPLCONFIGDIR to a writable directory for matplotlib configuration data

    It's /path/matplotlibrc and not /path/.matplotlibrc or anything
    like that?

    On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom > <mdroe@…86… <mailto:mdroe@…86…>> wrote:

        Just throwing out a suggestion here: You could try putting a
        matplotlibrc file in the same directory as your Python script
        -- it will use that instead of the one in ~/.matplotlib.

        Cheers,
        Mike

        "Jonathan Hayward, http://JonathansCorner.com" wrote:

            I have a PHP script which authenticates a user and I am
            trying to get the PHP script to wrap a Python script using
            matplotlib.

            As it is, the script mostly works when invoked from the
            command line or as its own CGI script. When I call it from
            a PHP script, it doesn't produce output, and testing found
            that when I call a Python script from a PHP script, output
            works before but not after "import matplotlib": if the PHP
            script calls a script of:

            #!/usr/bin/python
            print "Before import matplotlib."
            import matplotlib;
            print "After import matplotlib."

            the first print statement succeeds but the second one
            fails; the server log shows a crash of:

            Before import matplotlib.Traceback (most recent call last):
             File "/home/jhayward/bintmp/test.py", line 5, in <module>
               import matplotlib;
             File
            "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
            line 639, in <module>
               rcParams = rc_params()
             File
            "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
            line 562, in rc_params
               fname = matplotlib_fname()
             File
            "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
            line 513, in matplotlib_fname
               fname = os.path.join(get_configdir(), 'matplotlibrc')
             File
            "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
            line 207, in wrapper
               ret = func(*args, **kwargs)
             File
            "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
            line 403, in _get_configdir
               raise RuntimeError("Failed to create %s/.matplotlib;
            consider setting MPLCONFIGDIR to a writable directory for
            matplotlib configuration data"%h)
            RuntimeError: Failed to create /root/.matplotlib; consider
            setting MPLCONFIGDIR to a writable directory for
            matplotlib configuration data

            I think this error is somewhat misleading; it persisted
            after I ran a "chmod -R 1777 /root/.matplotlib".

            What is the proper way to adjust things so matplotlib will
            be happy with its .matplotlib directory?

            – – Jonathan Hayward, christos.jonathan.hayward@…287…
            <mailto:christos.jonathan.hayward@…287…>
            <mailto:christos.jonathan.hayward@…287…
            <mailto:christos.jonathan.hayward@…287…>>

            ** To see an award-winning website with stories, essays,
            artwork,
            ** games, and a four-dimensional maze, why not visit my
            home page?
            ** All of this is waiting for you at
            http://JonathansCorner.com

            ++ Would you like to curl up with one of my hardcover books?
            ++ You can now get my books from http://CJSHayward.com
            ------------------------------------------------------------------------

            -------------------------------------------------------------------------
            This SF.Net email is sponsored by the Moblin Your Move
            Developer's challenge
            Build the coolest Linux based applications with Moblin SDK
            & win great prizes
            Grand prize is a trip for two to an Open Source event
            anywhere in the world
            http://moblin-contest.org/redirect.php?banner_id=100&url=/
            <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
            ------------------------------------------------------------------------

            _______________________________________________
            Matplotlib-users mailing list
            Matplotlib-users@lists.sourceforge.net
            <mailto: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

    – – Jonathan Hayward, christos.jonathan.hayward@…287…
    <mailto:christos.jonathan.hayward@…287…>

    ** To see an award-winning website with stories, essays, artwork,
    ** games, and a four-dimensional maze, why not visit my home page?
    ** All of this is waiting for you at http://JonathansCorner.com

    ++ Would you like to curl up with one of my hardcover books?
    ++ You can now get my books from http://CJSHayward.com


– Jonathan Hayward, christos.jonathan.hayward@…287… <mailto:christos.jonathan.hayward@…287…>

** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?
++ You can now get my books from http://CJSHayward.com

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

I found a reason for the behavior:

The script was running as
user apache, but trying to open /root/.matplotlib, and /root was mode
0700. It stopped crashing on import after I made /root mode 0711.

This is somewhat surprising behavior to me; shouldn’t it be defaulting to something besides expected access to ~root?

···

On Fri, Aug 1, 2008 at 11:38 AM, Jonathan Hayward, http://JonathansCorner.com <jonathan.hayward@…789…> wrote:

Tried that and reran it; I’m getting substantially the same stacktrace:

File “/home/jhayward/bintmp/test.py”, line 5, in
import matplotlib;

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in
rcParams = rc_params()
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params

fname = matplotlib_fname()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname
fname = os.path.join(get_configdir(), ‘matplotlibrc’)
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper

ret = func(*args, **kwargs)

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir
raise RuntimeError(“Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data”%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

It’s /path/matplotlibrc and not /path/.matplotlibrc or anything like that?

On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom <mdroe@…86…> wrote:

Just throwing out a suggestion here: You could try putting a matplotlibrc file in the same directory as your Python script – it will use that instead of the one in ~/.matplotlib.

Cheers,

Mike

“Jonathan Hayward, http://JonathansCorner.com” wrote:

I have a PHP script which authenticates a user and I am trying to get the PHP script to wrap a Python script using matplotlib.

As it is, the script mostly works when invoked from the command line or as its own CGI script. When I call it from a PHP script, it doesn’t produce output, and testing found that when I call a Python script from a PHP script, output works before but not after “import matplotlib”: if the PHP script calls a script of:

#!/usr/bin/python

print “Before import matplotlib.”

import matplotlib;

print “After import matplotlib.”

the first print statement succeeds but the second one fails; the server log shows a crash of:

Before import matplotlib.Traceback (most recent call last):

File “/home/jhayward/bintmp/test.py”, line 5, in

import matplotlib;

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in

rcParams = rc_params()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params

fname = matplotlib_fname()

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname

fname = os.path.join(get_configdir(), 'matplotlibrc')

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper

ret = func(*args, **kwargs)

File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir

raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

I think this error is somewhat misleading; it persisted after I ran a “chmod -R 1777 /root/.matplotlib”.

What is the proper way to adjust things so matplotlib will be happy with its .matplotlib directory?

– Jonathan Hayward, christos.jonathan.hayward@…287… mailto:christos.jonathan.hayward@...287...

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?

** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com



This SF.Net email is sponsored by the Moblin Your Move Developer’s challenge

Build the coolest Linux based applications with Moblin SDK & win great prizes

Grand prize is a trip for two to an Open Source event anywhere in the world

http://moblin-contest.org/redirect.php?banner_id=100&url=/



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


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com

User apache exists with home directory /var/www, which exists.

···

On Fri, Aug 1, 2008 at 11:59 AM, Michael Droettboom <mdroe@…86…> wrote:

It’s supposed to default to the current user’s home directory. Perhaps “apache” doesn’t have a home directory?

Cheers,

Mike

“Jonathan Hayward, http://JonathansCorner.com” wrote:

I found a reason for the behavior:

The script was running as user apache, but trying to open /root/.matplotlib, and /root was mode 0700. It stopped crashing on import after I made /root mode 0711.

This is somewhat surprising behavior to me; shouldn’t it be defaulting to something besides expected access to ~root?

On Fri, Aug 1, 2008 at 11:38 AM, Jonathan Hayward, http://JonathansCorner.com <jonathan.hayward@…789… mailto:jonathan.hayward@...789...> wrote:

Tried that and reran it; I'm getting substantially the same

stacktrace:





  File "/home/jhayward/bintmp/test.py", line 5, in <module>

    import matplotlib;

  File

"/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

639, in <module>

    rcParams = rc_params()

  File

"/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

562, in rc_params

    fname = matplotlib_fname()

  File

"/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

513, in matplotlib_fname

    fname = os.path.join(get_configdir(), 'matplotlibrc')

  File

"/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

207, in wrapper

    ret = func(*args, **kwargs)

  File

"/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

403, in _get_configdir

    raise RuntimeError("Failed to create %s/.matplotlib; consider

setting MPLCONFIGDIR to a writable directory for matplotlib

configuration data"%h)

RuntimeError: Failed to create /root/.matplotlib; consider setting

MPLCONFIGDIR to a writable directory for matplotlib configuration data



It's /path/matplotlibrc and not /path/.matplotlibrc or anything

like that?





On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom > > <mdroe@...86... <mailto:mdroe@...86...>> wrote:



    Just throwing out a suggestion here: You could try putting a

    matplotlibrc file in the same directory as your Python script

    -- it will use that instead of the one in ~/.matplotlib.



    Cheers,

    Mike





    "Jonathan Hayward, [http://JonathansCorner.com](http://JonathansCorner.com)" wrote:



        I have a PHP script which authenticates a user and I am

        trying to get the PHP script to wrap a Python script using

        matplotlib.



        As it is, the script mostly works when invoked from the

        command line or as its own CGI script. When I call it from

        a PHP script, it doesn't produce output, and testing found

        that when I call a Python script from a PHP script, output

        works before but not after "import matplotlib": if the PHP

        script calls a script of:



        #!/usr/bin/python

        print "Before import matplotlib."

        import matplotlib;

        print "After import matplotlib."



        the first print statement succeeds but the second one

        fails; the server log shows a crash of:



        Before import matplotlib.Traceback (most recent call last):

         File "/home/jhayward/bintmp/test.py", line 5, in <module>

           import matplotlib;

         File

        "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

        line 639, in <module>

           rcParams = rc_params()

         File

        "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

        line 562, in rc_params

           fname = matplotlib_fname()

         File

        "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

        line 513, in matplotlib_fname

           fname = os.path.join(get_configdir(), 'matplotlibrc')

         File

        "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

        line 207, in wrapper

           ret = func(*args, **kwargs)

         File

        "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

        line 403, in _get_configdir

           raise RuntimeError("Failed to create %s/.matplotlib;

        consider setting MPLCONFIGDIR to a writable directory for

        matplotlib configuration data"%h)

        RuntimeError: Failed to create /root/.matplotlib; consider

        setting MPLCONFIGDIR to a writable directory for

        matplotlib configuration data



        I think this error is somewhat misleading; it persisted

        after I ran a "chmod -R 1777 /root/.matplotlib".



        What is the proper way to adjust things so matplotlib will

        be happy with its .matplotlib directory?



        --            -- Jonathan Hayward, christos.jonathan.hayward@...287...

        <mailto:christos.jonathan.hayward@...287...>

        <mailto:christos.jonathan.hayward@...287...

        <mailto:christos.jonathan.hayward@...287...>>





        ** To see an award-winning website with stories, essays,

        artwork,

        ** games, and a four-dimensional maze, why not visit my

        home page?

        ** All of this is waiting for you at

        [http://JonathansCorner.com](http://JonathansCorner.com)



        ++ Would you like to curl up with one of my hardcover books?

        ++ You can now get my books from [http://CJSHayward.com](http://CJSHayward.com)

        ------------------------------------------------------------------------



        -------------------------------------------------------------------------

        This SF.Net email is sponsored by the Moblin Your Move

        Developer's challenge

        Build the coolest Linux based applications with Moblin SDK

        & win great prizes

        Grand prize is a trip for two to an Open Source event

        anywhere in the world

        [http://moblin-contest.org/redirect.php?banner_id=100&url=/](http://moblin-contest.org/redirect.php?banner_id=100&url=/)

        <[http://moblin-contest.org/redirect.php?banner_id=100&url=/](http://moblin-contest.org/redirect.php?banner_id=100&url=/)>

        ------------------------------------------------------------------------



        _______________________________________________

        Matplotlib-users mailing list

        Matplotlib-users@lists.sourceforge.net

mailto:Matplotlib-users@lists.sourceforge.net

        [https://lists.sourceforge.net/lists/listinfo/matplotlib-users](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









--    -- Jonathan Hayward, christos.jonathan.hayward@...287...

mailto:christos.jonathan.hayward@...287...

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?

** All of this is waiting for you at [http://JonathansCorner.com](http://JonathansCorner.com)



++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from [http://CJSHayward.com](http://CJSHayward.com)

– Jonathan Hayward, christos.jonathan.hayward@…287… mailto:christos.jonathan.hayward@...287...

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?

** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com

Michael Droettboom

Science Software Branch

Operations and Engineering Division

Space Telescope Science Institute

Operated by AURA for NASA


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com

Below is the code in mpl that actually does the lookup. To get to the bottom of this, I would try to figure out in your Apache/PHP environment what

  a) what os.path.expanduser("~") gives

  b) what the values of the environment variables "HOME", "USERPROFILE", "USER", and "TMP" are.

I suspect either matplotlib is not getting run under user 'apache' as it should, or there is something fishy about the environment.

Cheers,
Mike

def _get_home():
    """Find user's home directory if possible.
    Otherwise raise error.

    :see: http://mail.python.org/pipermail/python-list/2005-February/263921.html
    """
    path=''
    try:
        path=os.path.expanduser("~")
    except:
        pass
    if not os.path.isdir(path):
        for evar in ('HOME', 'USERPROFILE', 'TMP'):
            try:
                path = os.environ[evar]
                if os.path.isdir(path):
                    break
            except: pass
    if path:
        return path
    else:
        raise RuntimeError('please define environment variable $HOME')

get_home = verbose.wrap('$HOME=%s', _get_home, always=False)

def _get_configdir():
    """
    Return the string representing the configuration dir.

    default is HOME/.matplotlib. you can override this with the
    MPLCONFIGDIR environment variable
    """

    configdir = os.environ.get('MPLCONFIGDIR')
    if configdir is not None:
        if not _is_writable_dir(configdir):
            raise RuntimeError('Could not write to MPLCONFIGDIR="%s"'%configdir)
        return configdir

    h = get_home()
    p = os.path.join(get_home(), '.matplotlib')

    if os.path.exists(p):
        if not _is_writable_dir(p):
            raise RuntimeError("'%s' is not a writable dir; you must set %s/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored "% (h, h))
    else:
        if not _is_writable_dir(h):
            raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)

        os.mkdir(p)

"Jonathan Hayward, http://JonathansCorner.com" wrote:

···

User apache exists with home directory /var/www, which exists.

On Fri, Aug 1, 2008 at 11:59 AM, Michael Droettboom <mdroe@…86… > <mailto:mdroe@…86…>> wrote:

    It's supposed to default to the current user's home directory.
     Perhaps "apache" doesn't have a home directory?

    Cheers,
    Mike

    "Jonathan Hayward, http://JonathansCorner.com" wrote:

        I found a reason for the behavior:

        The script was running as user apache, but trying to open
        /root/.matplotlib, and /root was mode 0700. It stopped
        crashing on import after I made /root mode 0711.

        This is somewhat surprising behavior to me; shouldn't it be
        defaulting to something besides expected access to ~root?

        On Fri, Aug 1, 2008 at 11:38 AM, Jonathan Hayward, > http://JonathansCorner.com <jonathan.hayward@…789… > <mailto:jonathan.hayward@…789…> > <mailto:jonathan.hayward@…789… > <mailto:jonathan.hayward@…789…>>> wrote:

           Tried that and reran it; I'm getting substantially the same
           stacktrace:

             File "/home/jhayward/bintmp/test.py", line 5, in <module>
               import matplotlib;
             File
                  "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
           639, in <module>
               rcParams = rc_params()
             File
                  "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
           562, in rc_params
               fname = matplotlib_fname()
             File
                  "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
           513, in matplotlib_fname
               fname = os.path.join(get_configdir(), 'matplotlibrc')
             File
                  "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
           207, in wrapper
               ret = func(*args, **kwargs)
             File
                  "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
           403, in _get_configdir
               raise RuntimeError("Failed to create %s/.matplotlib;
        consider
           setting MPLCONFIGDIR to a writable directory for matplotlib
           configuration data"%h)
           RuntimeError: Failed to create /root/.matplotlib; consider
        setting
           MPLCONFIGDIR to a writable directory for matplotlib
        configuration data

           It's /path/matplotlibrc and not /path/.matplotlibrc or anything
           like that?

           On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom > <mdroe@…86… <mailto:mdroe@…86…> > <mailto:mdroe@…86…>> wrote:

               Just throwing out a suggestion here: You could try
        putting a
               matplotlibrc file in the same directory as your Python
        script
               -- it will use that instead of the one in ~/.matplotlib.

               Cheers,
               Mike

               "Jonathan Hayward, http://JonathansCorner.com" wrote:

                   I have a PHP script which authenticates a user and I am
                   trying to get the PHP script to wrap a Python
        script using
                   matplotlib.

                   As it is, the script mostly works when invoked from the
                   command line or as its own CGI script. When I call
        it from
                   a PHP script, it doesn't produce output, and
        testing found
                   that when I call a Python script from a PHP script,
        output
                   works before but not after "import matplotlib": if
        the PHP
                   script calls a script of:

                   #!/usr/bin/python
                   print "Before import matplotlib."
                   import matplotlib;
                   print "After import matplotlib."

                   the first print statement succeeds but the second one
                   fails; the server log shows a crash of:

                   Before import matplotlib.Traceback (most recent
        call last):
                    File "/home/jhayward/bintmp/test.py", line 5, in
        <module>
                      import matplotlib;
                    File
                          "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                   line 639, in <module>
                      rcParams = rc_params()
                    File
                          "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                   line 562, in rc_params
                      fname = matplotlib_fname()
                    File
                          "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                   line 513, in matplotlib_fname
                      fname = os.path.join(get_configdir(),
        'matplotlibrc')
                    File
                          "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                   line 207, in wrapper
                      ret = func(*args, **kwargs)
                    File
                          "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                   line 403, in _get_configdir
                      raise RuntimeError("Failed to create %s/.matplotlib;
                   consider setting MPLCONFIGDIR to a writable
        directory for
                   matplotlib configuration data"%h)
                   RuntimeError: Failed to create /root/.matplotlib;
        consider
                   setting MPLCONFIGDIR to a writable directory for
                   matplotlib configuration data

                   I think this error is somewhat misleading; it persisted
                   after I ran a "chmod -R 1777 /root/.matplotlib".

                   What is the proper way to adjust things so
        matplotlib will
                   be happy with its .matplotlib directory?

                   – – Jonathan Hayward,
        christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
                   <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>
                   <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
                   <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>>

                   ** To see an award-winning website with stories,
        essays,
                   artwork,
                   ** games, and a four-dimensional maze, why not visit my
                   home page?
                   ** All of this is waiting for you at
                   http://JonathansCorner.com

                   ++ Would you like to curl up with one of my
        hardcover books?
                   ++ You can now get my books from http://CJSHayward.com
                          ------------------------------------------------------------------------

                          -------------------------------------------------------------------------
                   This SF.Net email is sponsored by the Moblin Your Move
                   Developer's challenge
                   Build the coolest Linux based applications with
        Moblin SDK
                   & win great prizes
                   Grand prize is a trip for two to an Open Source event
                   anywhere in the world
                          http://moblin-contest.org/redirect.php?banner_id=100&url=/
        <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
                          <http://moblin-contest.org/redirect.php?banner_id=100&url=/
        <http://moblin-contest.org/redirect.php?banner_id=100&url=/>>
                          ------------------------------------------------------------------------

                   _______________________________________________
                   Matplotlib-users mailing list
                   Matplotlib-users@lists.sourceforge.net
        <mailto:Matplotlib-users@lists.sourceforge.net>
                   <mailto:Matplotlib-users@lists.sourceforge.net
        <mailto: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

           – – Jonathan Hayward,
        christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
           <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>

           ** To see an award-winning website with stories, essays,
        artwork,
           ** games, and a four-dimensional maze, why not visit my
        home page?
           ** All of this is waiting for you at http://JonathansCorner.com

           ++ Would you like to curl up with one of my hardcover books?
           ++ You can now get my books from http://CJSHayward.com

        – – Jonathan Hayward, christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
        <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>

        ** To see an award-winning website with stories, essays, artwork,
        ** games, and a four-dimensional maze, why not visit my home page?
        ** All of this is waiting for you at http://JonathansCorner.com

        ++ Would you like to curl up with one of my hardcover books?
        ++ You can now get my books from http://CJSHayward.com

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


– Jonathan Hayward, christos.jonathan.hayward@…287… <mailto:christos.jonathan.hayward@…287…>

** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?
++ You can now get my books from http://CJSHayward.com

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

It looks like an apache that thinks it’s root:

os.system(“whoami”)
print “

print os.geteuid()
print “

print os.getuid()

print “

print os.path.expanduser("~")
print “

print os.getenv(“HOME”)
print “

print os.getenv(“USERPROFILE”)

print “

print os.getenv(“USER”)
print “

print os.getenv(“TMP”)
print “

produces:

apache

81

81

/root

/root

None

root

None

So I should adjust the system so a confused apache-owned process that thinks it’s root will run? Or are there features to ask PHP to spawn subprocesses that know who they’re running as? (or is that something beside the point of this list?)

···

On Fri, Aug 1, 2008 at 1:09 PM, Michael Droettboom <mdroe@…86…> wrote:

Below is the code in mpl that actually does the lookup. To get to the bottom of this, I would try to figure out in your Apache/PHP environment what

a) what os.path.expanduser("~") gives

b) what the values of the environment variables “HOME”, “USERPROFILE”, “USER”, and “TMP” are.

I suspect either matplotlib is not getting run under user ‘apache’ as it should, or there is something fishy about the environment.

Cheers,

Mike

def _get_home():

“”"Find user’s home directory if possible.

Otherwise raise error.

:see: http://mail.python.org/pipermail/python-list/2005-February/263921.html

“”"

path=’’

try:

   path=os.path.expanduser("~")

except:

   pass

if not os.path.isdir(path):

   for evar in ('HOME', 'USERPROFILE', 'TMP'):

       try:

           path = os.environ[evar]

           if os.path.isdir(path):

               break

       except: pass

if path:

   return path

else:

   raise RuntimeError('please define environment variable $HOME')

get_home = verbose.wrap(’$HOME=%s’, _get_home, always=False)

def _get_configdir():

“”"

Return the string representing the configuration dir.

default is HOME/.matplotlib. you can override this with the

MPLCONFIGDIR environment variable

“”"

configdir = os.environ.get(‘MPLCONFIGDIR’)

if configdir is not None:

   if not _is_writable_dir(configdir):

       raise RuntimeError('Could not write to MPLCONFIGDIR="%s"'%configdir)

   return configdir

h = get_home()

p = os.path.join(get_home(), ‘.matplotlib’)

if os.path.exists§:

   if not _is_writable_dir(p):

       raise RuntimeError("'%s' is not a writable dir; you must set %s/.matplotlib to be a writable dir.  You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored "% (h, h))

else:

   if not _is_writable_dir(h):


       raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)

os.mkdir§

“Jonathan Hayward, http://JonathansCorner.com” wrote:

User apache exists with home directory /var/www, which exists.

On Fri, Aug 1, 2008 at 11:59 AM, Michael Droettboom <mdroe@…86… mailto:mdroe@...86...> wrote:

It's supposed to default to the current user's home directory.

 Perhaps "apache" doesn't have a home directory?





Cheers,

Mike



"Jonathan Hayward, [http://JonathansCorner.com](http://JonathansCorner.com)" wrote:



    I found a reason for the behavior:



    The script was running as user apache, but trying to open

    /root/.matplotlib, and /root was mode 0700. It stopped

    crashing on import after I made /root mode 0711.



    This is somewhat surprising behavior to me; shouldn't it be

    defaulting to something besides expected access to ~root?



    On Fri, Aug 1, 2008 at 11:38 AM, Jonathan Hayward,

    [http://JonathansCorner.com](http://JonathansCorner.com) <jonathan.hayward@...789...

    <mailto:jonathan.hayward@...789...>

    <mailto:jonathan.hayward@...789...

    <mailto:jonathan.hayward@...789...>>> wrote:



       Tried that and reran it; I'm getting substantially the same

       stacktrace:





         File "/home/jhayward/bintmp/test.py", line 5, in <module>

           import matplotlib;

         File

             "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

       639, in <module>

           rcParams = rc_params()

         File

             "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

       562, in rc_params

           fname = matplotlib_fname()

         File

             "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

       513, in matplotlib_fname

           fname = os.path.join(get_configdir(), 'matplotlibrc')

         File

             "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

       207, in wrapper

           ret = func(*args, **kwargs)

         File

             "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line

       403, in _get_configdir

           raise RuntimeError("Failed to create %s/.matplotlib;

    consider

       setting MPLCONFIGDIR to a writable directory for matplotlib

       configuration data"%h)

       RuntimeError: Failed to create /root/.matplotlib; consider

    setting

       MPLCONFIGDIR to a writable directory for matplotlib

    configuration data



       It's /path/matplotlibrc and not /path/.matplotlibrc or anything

       like that?





       On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom > >  > >            <mdroe@...86... <mailto:mdroe@...86...> > > <mailto:mdroe@...86... <mailto:mdroe@...86...>>> wrote:



           Just throwing out a suggestion here: You could try

    putting a

           matplotlibrc file in the same directory as your Python

    script

           -- it will use that instead of the one in ~/.matplotlib.



           Cheers,

           Mike





           "Jonathan Hayward, [http://JonathansCorner.com](http://JonathansCorner.com)" wrote:



               I have a PHP script which authenticates a user and I am

               trying to get the PHP script to wrap a Python

    script using

               matplotlib.



               As it is, the script mostly works when invoked from the

               command line or as its own CGI script. When I call

    it from

               a PHP script, it doesn't produce output, and

    testing found

               that when I call a Python script from a PHP script,

    output

               works before but not after "import matplotlib": if

    the PHP

               script calls a script of:



               #!/usr/bin/python

               print "Before import matplotlib."

               import matplotlib;

               print "After import matplotlib."



               the first print statement succeeds but the second one

               fails; the server log shows a crash of:



               Before import matplotlib.Traceback (most recent

    call last):

                File "/home/jhayward/bintmp/test.py", line 5, in

    <module>

                  import matplotlib;

                File

                     "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

               line 639, in <module>

                  rcParams = rc_params()

                File

                     "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

               line 562, in rc_params

                  fname = matplotlib_fname()

                File

                     "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

               line 513, in matplotlib_fname

                  fname = os.path.join(get_configdir(),

    'matplotlibrc')

                File

                     "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

               line 207, in wrapper

                  ret = func(*args, **kwargs)

                File

                     "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",

               line 403, in _get_configdir

                  raise RuntimeError("Failed to create %s/.matplotlib;

               consider setting MPLCONFIGDIR to a writable

    directory for

               matplotlib configuration data"%h)

               RuntimeError: Failed to create /root/.matplotlib;

    consider

               setting MPLCONFIGDIR to a writable directory for

               matplotlib configuration data



               I think this error is somewhat misleading; it persisted

               after I ran a "chmod -R 1777 /root/.matplotlib".



               What is the proper way to adjust things so

    matplotlib will

               be happy with its .matplotlib directory?



               --            -- Jonathan Hayward,

    christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>

               <mailto:christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>>

               <mailto:christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>

               <mailto:christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>>>





               ** To see an award-winning website with stories,

    essays,

               artwork,

               ** games, and a four-dimensional maze, why not visit my

               home page?

               ** All of this is waiting for you at

               [http://JonathansCorner.com](http://JonathansCorner.com)



               ++ Would you like to curl up with one of my

    hardcover books?

               ++ You can now get my books from [http://CJSHayward.com](http://CJSHayward.com)

                     ------------------------------------------------------------------------



                     -------------------------------------------------------------------------

               This SF.Net email is sponsored by the Moblin Your Move

               Developer's challenge

               Build the coolest Linux based applications with

    Moblin SDK

               & win great prizes

               Grand prize is a trip for two to an Open Source event

               anywhere in the world

                     [http://moblin-contest.org/redirect.php?banner_id=100&url=/](http://moblin-contest.org/redirect.php?banner_id=100&url=/)

    <[http://moblin-contest.org/redirect.php?banner_id=100&url=/](http://moblin-contest.org/redirect.php?banner_id=100&url=/)>

                     <[http://moblin-contest.org/redirect.php?banner_id=100&url=/](http://moblin-contest.org/redirect.php?banner_id=100&url=/)

    <[http://moblin-contest.org/redirect.php?banner_id=100&url=/](http://moblin-contest.org/redirect.php?banner_id=100&url=/)>>

                     ------------------------------------------------------------------------



               _______________________________________________

               Matplotlib-users mailing list

               Matplotlib-users@lists.sourceforge.net

    <mailto:Matplotlib-users@lists.sourceforge.net>

               <mailto:Matplotlib-users@lists.sourceforge.net

    <mailto:Matplotlib-users@lists.sourceforge.net>>



                     [https://lists.sourceforge.net/lists/listinfo/matplotlib-users](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









       --    -- Jonathan Hayward,

    christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>

       <mailto:christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>>



       ** To see an award-winning website with stories, essays,

    artwork,

       ** games, and a four-dimensional maze, why not visit my

    home page?

       ** All of this is waiting for you at [http://JonathansCorner.com](http://JonathansCorner.com)



       ++ Would you like to curl up with one of my hardcover books?

       ++ You can now get my books from [http://CJSHayward.com](http://CJSHayward.com)









    --        -- Jonathan Hayward, christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>

    <mailto:christos.jonathan.hayward@...287...

    <mailto:christos.jonathan.hayward@...287...>>



    ** To see an award-winning website with stories, essays, artwork,

    ** games, and a four-dimensional maze, why not visit my home page?

    ** All of this is waiting for you at [http://JonathansCorner.com](http://JonathansCorner.com)



    ++ Would you like to curl up with one of my hardcover books?

    ++ You can now get my books from [http://CJSHayward.com](http://CJSHayward.com)

– Michael Droettboom

Science Software Branch

Operations and Engineering Division

Space Telescope Science Institute

Operated by AURA for NASA

– Jonathan Hayward, christos.jonathan.hayward@…287… mailto:christos.jonathan.hayward@...287...

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?

** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com

Michael Droettboom

Science Software Branch

Operations and Engineering Division

Space Telescope Science Institute

Operated by AURA for NASA


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,

** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?

++ You can now get my books from http://CJSHayward.com

This is getting a bit outside of my knowledge area, but it does look like the environment variables are not being set up correctly when the Python process is run. This is probably a more general apache/mod_php sort of question, but it would be great to post the answer here so we can add a solution to the matplotlib FAQ.

Cheers,
Mike

"Jonathan Hayward, http://JonathansCorner.com" wrote:

···

It looks like an apache that thinks it's root:

os.system("whoami")
print "<br>"
print os.geteuid()
print "<br>"
print os.getuid()
print "<br>"
print os.path.expanduser("~")
print "<br>"
print os.getenv("HOME")
print "<br>"
print os.getenv("USERPROFILE")
print "<br>"
print os.getenv("USER")
print "<br>"
print os.getenv("TMP")
print "<br>"

produces:

apache
81
/root
None
root
None

So I should adjust the system so a confused apache-owned process that thinks it's root will run? Or are there features to ask PHP to spawn subprocesses that know who they're running as? (or is that something beside the point of this list?)

On Fri, Aug 1, 2008 at 1:09 PM, Michael Droettboom <mdroe@…86… > <mailto:mdroe@…86…>> wrote:

    Below is the code in mpl that actually does the lookup. To get to
    the bottom of this, I would try to figure out in your Apache/PHP
    environment what

     a) what os.path.expanduser("~") gives

     b) what the values of the environment variables "HOME",
    "USERPROFILE", "USER", and "TMP" are.

    I suspect either matplotlib is not getting run under user 'apache'
    as it should, or there is something fishy about the environment.

    Cheers,
    Mike

    def _get_home():
      """Find user's home directory if possible.
      Otherwise raise error.

      :see:
     http://mail.python.org/pipermail/python-list/2005-February/263921.html
      """
      path=''
      try:
          path=os.path.expanduser("~")
      except:
          pass
      if not os.path.isdir(path):
          for evar in ('HOME', 'USERPROFILE', 'TMP'):
              try:
                  path = os.environ[evar]
                  if os.path.isdir(path):
                      break
              except: pass
      if path:
          return path
      else:
          raise RuntimeError('please define environment variable $HOME')

    get_home = verbose.wrap('$HOME=%s', _get_home, always=False)

    def _get_configdir():
      """
      Return the string representing the configuration dir.

      default is HOME/.matplotlib. you can override this with the
      MPLCONFIGDIR environment variable
      """

      configdir = os.environ.get('MPLCONFIGDIR')
      if configdir is not None:
          if not _is_writable_dir(configdir):
              raise RuntimeError('Could not write to
    MPLCONFIGDIR="%s"'%configdir)
          return configdir

      h = get_home()
      p = os.path.join(get_home(), '.matplotlib')

      if os.path.exists(p):
          if not _is_writable_dir(p):
              raise RuntimeError("'%s' is not a writable dir; you must
    set %s/.matplotlib to be a writable dir. You can also set
    environment variable MPLCONFIGDIR to any writable directory where
    you want matplotlib data stored "% (h, h))
      else:
          if not _is_writable_dir(h):

              raise RuntimeError("Failed to create %s/.matplotlib;
    consider setting MPLCONFIGDIR to a writable directory for
    matplotlib configuration data"%h)

          os.mkdir(p)

    "Jonathan Hayward, http://JonathansCorner.com" wrote:

        User apache exists with home directory /var/www, which exists.

        On Fri, Aug 1, 2008 at 11:59 AM, Michael Droettboom > <mdroe@…86… <mailto:mdroe@…86…> > <mailto:mdroe@…86…>> wrote:

           It's supposed to default to the current user's home directory.
            Perhaps "apache" doesn't have a home directory?

           Cheers,
           Mike

           "Jonathan Hayward, http://JonathansCorner.com" wrote:

               I found a reason for the behavior:

               The script was running as user apache, but trying to open
               /root/.matplotlib, and /root was mode 0700. It stopped
               crashing on import after I made /root mode 0711.

               This is somewhat surprising behavior to me; shouldn't it be
               defaulting to something besides expected access to ~root?

               On Fri, Aug 1, 2008 at 11:38 AM, Jonathan Hayward,
               http://JonathansCorner.com <jonathan.hayward@…789…
        <mailto:jonathan.hayward@…789…>
               <mailto:jonathan.hayward@…789…
        <mailto:jonathan.hayward@…789…>>
               <mailto:jonathan.hayward@…789…
        <mailto:jonathan.hayward@…789…>
               <mailto:jonathan.hayward@…789…
        <mailto:jonathan.hayward@…789…>>>> wrote:

                  Tried that and reran it; I'm getting substantially
        the same
                  stacktrace:

                    File "/home/jhayward/bintmp/test.py", line 5, in
        <module>
                      import matplotlib;
                    File
                               "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
                  639, in <module>
                      rcParams = rc_params()
                    File
                               "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
                  562, in rc_params
                      fname = matplotlib_fname()
                    File
                               "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
                  513, in matplotlib_fname
                      fname = os.path.join(get_configdir(),
        'matplotlibrc')
                    File
                               "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
                  207, in wrapper
                      ret = func(*args, **kwargs)
                    File
                               "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py", line
                  403, in _get_configdir
                      raise RuntimeError("Failed to create %s/.matplotlib;
               consider
                  setting MPLCONFIGDIR to a writable directory for
        matplotlib
                  configuration data"%h)
                  RuntimeError: Failed to create /root/.matplotlib;
        consider
               setting
                  MPLCONFIGDIR to a writable directory for matplotlib
               configuration data

                  It's /path/matplotlibrc and not /path/.matplotlibrc
        or anything
                  like that?

                  On Fri, Aug 1, 2008 at 10:51 AM, Michael Droettboom > <mdroe@…86… <mailto:mdroe@…86…> > <mailto:mdroe@…86…> > <mailto:mdroe@…86… > <mailto:mdroe@…86…>>> wrote:

                      Just throwing out a suggestion here: You could try
               putting a
                      matplotlibrc file in the same directory as your
        Python
               script
                      -- it will use that instead of the one in
        ~/.matplotlib.

                      Cheers,
                      Mike

                      "Jonathan Hayward, http://JonathansCorner.com"
        wrote:

                          I have a PHP script which authenticates a
        user and I am
                          trying to get the PHP script to wrap a Python
               script using
                          matplotlib.

                          As it is, the script mostly works when
        invoked from the
                          command line or as its own CGI script. When
        I call
               it from
                          a PHP script, it doesn't produce output, and
               testing found
                          that when I call a Python script from a PHP
        script,
               output
                          works before but not after "import
        matplotlib": if
               the PHP
                          script calls a script of:

                          #!/usr/bin/python
                          print "Before import matplotlib."
                          import matplotlib;
                          print "After import matplotlib."

                          the first print statement succeeds but the
        second one
                          fails; the server log shows a crash of:

                          Before import matplotlib.Traceback (most recent
               call last):
                           File "/home/jhayward/bintmp/test.py", line
        5, in
               <module>
                             import matplotlib;
                           File
                                       "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                          line 639, in <module>
                             rcParams = rc_params()
                           File
                                       "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                          line 562, in rc_params
                             fname = matplotlib_fname()
                           File
                                       "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                          line 513, in matplotlib_fname
                             fname = os.path.join(get_configdir(),
               'matplotlibrc')
                           File
                                       "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                          line 207, in wrapper
                             ret = func(*args, **kwargs)
                           File
                                       "/usr/lib64/python2.5/site-packages/matplotlib/__init__.py",
                          line 403, in _get_configdir
                             raise RuntimeError("Failed to create
        %s/.matplotlib;
                          consider setting MPLCONFIGDIR to a writable
               directory for
                          matplotlib configuration data"%h)
                          RuntimeError: Failed to create
        /root/.matplotlib;
               consider
                          setting MPLCONFIGDIR to a writable directory for
                          matplotlib configuration data

                          I think this error is somewhat misleading;
        it persisted
                          after I ran a "chmod -R 1777 /root/.matplotlib".

                          What is the proper way to adjust things so
               matplotlib will
                          be happy with its .matplotlib directory?

                          – – Jonathan Hayward,
               christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>
                          <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>>
                          <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>
                          <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>>>

                          ** To see an award-winning website with stories,
               essays,
                          artwork,
                          ** games, and a four-dimensional maze, why
        not visit my
                          home page?
                          ** All of this is waiting for you at
                          http://JonathansCorner.com

                          ++ Would you like to curl up with one of my
               hardcover books?
                          ++ You can now get my books from
        http://CJSHayward.com
                                       ------------------------------------------------------------------------

                                       -------------------------------------------------------------------------
                          This SF.Net email is sponsored by the Moblin
        Your Move
                          Developer's challenge
                          Build the coolest Linux based applications with
               Moblin SDK
                          & win great prizes
                          Grand prize is a trip for two to an Open
        Source event
                          anywhere in the world
                                       http://moblin-contest.org/redirect.php?banner_id=100&url=/
        <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
                      <http://moblin-contest.org/redirect.php?banner_id=100&url=/
        <http://moblin-contest.org/redirect.php?banner_id=100&url=/>>
                                       <http://moblin-contest.org/redirect.php?banner_id=100&url=/
        <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
                      <http://moblin-contest.org/redirect.php?banner_id=100&url=/
        <http://moblin-contest.org/redirect.php?banner_id=100&url=/>>>
                                       ------------------------------------------------------------------------

                          _______________________________________________
                          Matplotlib-users mailing list
                          Matplotlib-users@lists.sourceforge.net
        <mailto:Matplotlib-users@lists.sourceforge.net>
               <mailto:Matplotlib-users@lists.sourceforge.net
        <mailto:Matplotlib-users@lists.sourceforge.net>>
                                 <mailto:Matplotlib-users@lists.sourceforge.net
        <mailto:Matplotlib-users@lists.sourceforge.net>
               <mailto:Matplotlib-users@lists.sourceforge.net
        <mailto: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

                  – – Jonathan Hayward,
               christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>
                  <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>>

                  ** To see an award-winning website with stories, essays,
               artwork,
                  ** games, and a four-dimensional maze, why not visit my
               home page?
                  ** All of this is waiting for you at
        http://JonathansCorner.com

                  ++ Would you like to curl up with one of my
        hardcover books?
                  ++ You can now get my books from http://CJSHayward.com

               – – Jonathan Hayward,
        christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
               <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>>

               ** To see an award-winning website with stories,
        essays, artwork,
               ** games, and a four-dimensional maze, why not visit my
        home page?
               ** All of this is waiting for you at
        http://JonathansCorner.com

               ++ Would you like to curl up with one of my hardcover
        books?
               ++ You can now get my books from http://CJSHayward.com

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

        – – Jonathan Hayward, christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>
        <mailto:christos.jonathan.hayward@…287…
        <mailto:christos.jonathan.hayward@…287…>>

        ** To see an award-winning website with stories, essays, artwork,
        ** games, and a four-dimensional maze, why not visit my home page?
        ** All of this is waiting for you at http://JonathansCorner.com

        ++ Would you like to curl up with one of my hardcover books?
        ++ You can now get my books from http://CJSHayward.com

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


– Jonathan Hayward, christos.jonathan.hayward@…287… <mailto:christos.jonathan.hayward@…287…>

** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?
++ You can now get my books from http://CJSHayward.com

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

Jonathan,

If you did not get a response by now, you can try the following.

import os# set HOME environment variable to a directory the httpd server can write to
os.environ[ ‘HOME’ ] = ‘c:/www/app/tmp/’

Good luck.

-Rodney

···

From:
matplotlib-users-bounces@lists.sourceforge.net [mailto:matplotlib-users-bounces@lists.sourceforge.net] On Behalf Of “Jonathan Hayward, http://JonathansCorner.com
Sent: Friday, August 01, 2008 11:26 AM
To: Matplotlib
Subject:
[Matplotlib-users] Crash on import with CGI wrapped by PHP–unhappywith .matplotlib directory?

I have a PHP script which authenticates a user and I am trying to get the PHP script to wrap a Python script using matplotlib.

As it is, the script mostly works when invoked from the command line or as its own CGI script. When I call it from a PHP script, it doesn’t produce output, and testing found that when I call a Python script from a PHP script, output works before but not after “import matplotlib”: if the PHP script calls a script of:

#!/usr/bin/python
print “Before import matplotlib.”
import matplotlib;
print “After import matplotlib.”

the first print statement succeeds but the second one fails; the server log shows a crash of:

Before import matplotlib.Traceback (most recent call last):
File “/home/jhayward/bintmp/test.py”, line 5, in
import matplotlib;
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 639, in
rcParams = rc_params()
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 562, in rc_params
fname = matplotlib_fname()
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 513, in matplotlib_fname
fname = os.path.join(get_configdir(), ‘matplotlibrc’)
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 207, in wrapper
ret = func(*args, **kwargs)
File “/usr/lib64/python2.5/site-packages/matplotlib/init.py”, line 403, in _get_configdir
raise RuntimeError(“Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data”%h)
RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

I think this error is somewhat misleading; it persisted after I ran a “chmod -R 1777 /root/.matplotlib”.

What is the proper way to adjust things so matplotlib will be happy with its .matplotlib directory?


– Jonathan Hayward, christos.jonathan.hayward@…287…

** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

++ Would you like to curl up with one of my hardcover books?
++ You can now get my books from http://CJSHayward.com