16

I am unable to import the pydot package in Spyder, Could you please help me out is there any other way to import it. I need it for decision tree visualization. The statement

import pydot

is not working.

0 _
  • 10,524
  • 11
  • 77
  • 109
Sanchit Aluna
  • 455
  • 2
  • 6
  • 20

4 Answers4

21
pip install pydot
pip install graphviz

there is a similar problemm: Keras: "RuntimeError: Failed to import pydot." after installing graphviz and pydot

pip installs pydot, but not GraphViz. The GraphViz binary files (dot, neato, etc.) need to be downloaded and installed separately from pydot. In addition, the location of these executables should be added to the $PATH environment variable (or equivalent in your operating system). Otherwise pydot won't find dot when looking in directories included in the current path.

0 _
  • 10,524
  • 11
  • 77
  • 109
Eugenie
  • 256
  • 1
  • 3
  • 6
5

Do you not know how to install pydot in python spyder? If you use Spyder on Windows, you could try to input code following in CMD( I have no idea whether it is effective on Linux):

conda install -c https://conda.binstar.org/sstromberg pydot

If it says 'InvocationException: GraphViz's executables not found' after you install pydot, you need install GraphViz as well:

conda install GraphViz
Chen Xu
  • 342
  • 1
  • 4
  • 14
  • if you not sure then don't put it as a answer – Mostafiz May 01 '16 at 09:06
  • 1
    Sorry, I am NOT "not sure". I am just not fully understand what is @Sanchit Aluna 's problem and the context the error happened. I think my answer will be helpful:) – Chen Xu May 01 '16 at 12:32
2

Try to command line with:

import pydot

If you get ImportError, just reinstall this module.

Maybe you have multiple installations of Python (e.g. 2.7 and 3.5). When installing you put the module in one Python and try to import in another.

Also, this problem can to occur due to the fact that instead install you just copied the file to your local directory. If yes, use pip or setuptools for install or add your local directory to sys.path.

0 _
  • 10,524
  • 11
  • 77
  • 109
JRazor
  • 2,707
  • 18
  • 27
  • Hi, If i comment the import pydot then how will it work. i have python in my computer that is the language i am using for importing pydot. it is not working . could you please elaborate what were you trying to say? – Sanchit Aluna Feb 03 '16 at 12:41
  • I have just 2.7 and how can i put in one and import in another. as i am new to python i am just giving 'import pydot' command in python nothing else. – Sanchit Aluna Feb 03 '16 at 12:49
  • Thanks for the suggestion but your suggestion could not help me out . Any other suggestion how to import pydot package in Python. i just i have to write import pydot apart from this i do not know any other procedure. Please suggest – Sanchit Aluna Feb 03 '16 at 13:25
  • 1
    @SanchitAluna It looks like you have not properly installed `pydot`. JRazor is suggesting that you reinstall. – zondo Feb 03 '16 at 13:35
  • Hi @zondo can you suggest me how do i reinstall as i am again typing only 'import pydot' is there any other words i have to type to reinstall – Sanchit Aluna Feb 03 '16 at 13:45
  • 1
    @SanchitAluna I don't mean `import`. I mean the `pydot` package is not on your computer. Therefore Python doesn't know where to find it. I would guess that you could install `pydot` by running `sudo pip install pydot` from the command-line, (not the Python shell). – zondo Feb 03 '16 at 14:04
  • Thankyou @Zondo and JRazor for the help. it works now, i have installed it from pip :) – Sanchit Aluna Feb 03 '16 at 15:48
2

You could install pydot and pyparsing using conda.

conda install -c anaconda pydot=1.2.3
conda install -c anaconda pyparsing=2.2.0
0 _
  • 10,524
  • 11
  • 77
  • 109
saneryee
  • 3,239
  • 31
  • 22