简体   繁体   中英

What is import gv in python?

I installed easy_install under windows, and installed pygraph but the commad import gv in the example taken from here doesn't work:

What is gv lib? what import gv does?

I get this error :

Traceback (most recent call last):
  File "C:\Python27\graph.py", line 11, in <module>
    import gv
ImportError: No module named gv

All the other imports works fine

Try to install libgv-python with your package manager. On Ubuntu:

sudo apt-get install libgv-python

From python-graph's "Issue 15: import gv" :

It appears that graphviz for windows has no python bindings, or they are not included with the installer, and not available elsewhere.

Furthermore, I can find no mention of libgv-python (the library which gv is from, I think) ever being available on windows.

You can workaround the absent gv.py by using the command line tools directly.

Assuming you're trying the example code , remove these lines:

sys.path.append('..')
sys.path.append('/usr/lib/graphviz/python/')
sys.path.append('/usr/lib64/graphviz/python/')
import gv

And remove these lines:

gvv = gv.readstring(dot)
gv.layout(gvv,'dot')
gv.render(gvv,'png','europe.png')

And add these lines instead, making sure the path to dot.exe is correct, or is otherwise in your PATH:

f = open('europe.dot', 'a')
f.write(dot)
f.close()
import os
command = '"C:\\Program Files\\Graphviz 2.28\\bin\\dot.exe" -Tpng europe.dot > europe.png'
print command
os.system(command)
os.system('europe.png')

This could have multiple problem sources:

  1. While installing, something went wrong and the module couldn't be installed.
  2. You haven't set your Python Path correctly.
  3. @second example: The module pygraph.readwrite could exists, but it's possible that it hasn't got a submodule called dot.

Of course there are sure other possibile problems, but I think this would be the most likely.

Edit: Have a look at this . Looks like it's the same problem as yours.

For the second problem eventually this discussion may also help.

This seems to be a common issue with python-graph, see the discussion at http://code.google.com/p/python-graph/issues/detail?id=15 . gv is GraphViz and apparently something with the place or the bindings of this library is wrong. You might have to modify sys.path , but it might be even more troublesome on Windows.

与graphviz-python对应的模块gv是graphviz的python绑定请参阅: http//www.graphviz.org/Home.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM