1
votes

I am using a graphviz library for Python.

When I run the script from terminal, the graph is created, but when I start the script from C program using posix_spawn, I get error message saying that

"ValueError: Program dot not found in path" (I have tried all options: 'neato', 'dot', 'twopi', 'circo', 'fdp', 'nop').

My Python script uses #!/usr/local/bin/python location. I have tried to explicitly use this path and tried out the same sequence:

import pygraphviz as pgv
G = pgv.AGraph(directed=True)
G.add_node(1)
G.get_node(1).attr['label'] = 'hi'
G.draw('test.png', prog='dot')

and it worked

I am lost why after calling script using posix_spawn, the graphviz library cannot find the path anymore.

EDIT:

After adding dot path to: bash_profile, bash_rc, and etc/paths, I get /usr/bin:/bin:/usr/sbin:/sbin when I try printing my path both from Python script and C program, while my echot $PATH has many lines.

Have also tried appending PATH from Python sys.path.append('/opt/local/bin/dot')

P.S. I am using Webots as my IDE

1

1 Answers

2
votes

The error message says that graphviz isn't in your path. Make sure $PATH contains the folder which contains dot and the rest of the graphviz tools.

[EDIT] I'm not sure where Webots gets its path from; my guess would be that Mac OS/X strips the PATH of processes which you start from the Desktop (or maybe the desktop process is started with a very basic PATH).

For such situations, I usually wrap the C program in an executable script that sets the environment (like the PATH) and then invokes the C program itself. When you execute the script from anywhere, the code will behave as expected.