Im running a code that needs pydot and graphviz. I am using python 3.5 and ubuntu 16.04 LTS 64 bit.

  File "/usr/local/lib/python3.5/dist-packages/keras/utils/vis_utils.py", line 17, in _check_pydot
    raise ImportError('Failed to import pydot. You must install pydot'
ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.

I googled a little then found that I can install pydot with the code pip install pydot. But I know get this error. I am noob in ubuntu and I dont understand what to do. so how do I install pydot ?

deeplearning@deep-learning-virtual-machine:~$ pip install pydot
Collecting pydot
Collecting pyparsing>=2.1.4 (from pydot)
  Using cached pyparsing-2.2.0-py2.py3-none-any.whl
Installing collected packages: pyparsing, pydot
  Found existing installation: pyparsing 2.0.3
    Uninstalling pyparsing-2.0.3:
Traceback (most recent call last):
  File "/usr/lib/python3.5/shutil.py", line 538, in move
    os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages/__pycache__/pyparsing.cpython-35.pyc' -> '/tmp/pip-45miiuxw-uninstall/usr/lib/python3/dist-packages/__pycache__/pyparsing.cpython-35.pyc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.5/dist-packages/pip/commands/install.py", line 342, in run
  File "/usr/local/lib/python3.5/dist-packages/pip/req/req_set.py", line 778, in install
  File "/usr/local/lib/python3.5/dist-packages/pip/req/req_install.py", line 754, in uninstall
  File "/usr/local/lib/python3.5/dist-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/usr/local/lib/python3.5/dist-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/usr/lib/python3.5/shutil.py", line 553, in move
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages/__pycache__/pyparsing.cpython-35.pyc'
  • 1
    pip install pydot>=1.2.4 and sudo apt-get install graphviz.
    – 0 _
    Oct 25, 2017 at 10:00

4 Answers 4


python-pydot and graphviz are in the default Ubuntu repositories in all currently supported versions of Ubuntu. In all currently supported versions of Ubuntu, open the terminal and type:

sudo apt install python-pydot python-pydot-ng graphviz # python-pydot-ng isn't in the 14.04 repos

This flowchart was created with graphviz in Ubuntu. Because graphviz uses the built-in dot programming language which is included in the graphviz package, the source code of the linked flowchart is editable in any text editor even if python-pydot is not installed.

I don't know why you would want to install pydot with pip when you can get it from the Ubuntu repositories, but to answer your question I tried installing pydot anyway in a Python virtual environment with pip3 install pydot and it worked, so it is possible that you need to update pip to the latest version with sudo -H pip3 install --upgrade pip. I used pip3 instead of pip because you wrote in your question that you are using Python 3.5.

  • wow thank you :) I have been following your comments as you updated it. It finally worked. Guess I need to google up more on ubuntu. pip, pip3, apt, apt-get... its all super confusing.
    – Kong
    May 20, 2017 at 7:36
  • In Ubuntu many packages from PyPI are included in the default Ubuntu repositories and their package names are usually prefaced with python- and similarly for pip3 packages their package names in the Ubuntu repos are usually prefaced with python3-
    – karel
    May 20, 2017 at 14:41
  • Installing packages directly from PyPI with pip is the recommended approach: the latest version (Ubuntu repositories can be outdated), managed with a requirements file when appropriate, and installed to a virtualenv; not to the system's site-packages.
    – 0 _
    Oct 25, 2017 at 9:59

From this answer on "Installing pydot and graphviz packages in Anaconda environment"

I had the same issue and solved it by (order is important):

  1. Installing graphviz, simply via sudo apt-get install graphviz
  2. Installing graphviz for Python via conda sudo ~/anaconda2/bin/conda install graphviz
  3. Finally, by installing pydot using conda sudo ~/anaconda2/bin/conda install pydot

This answer is overdue but this post helped me (together with this one that mentions the installation order), so hopefully this answer will help someone else. I'm using Ubuntu 14.04 and Python 2.7.

P.S. apparently, there could be some issues with step 1 of the above algorithm, this post mentions how to fix them.

  • 3
    Please do not plagiarize. It's not against the site rules, but it's certainly not cool. Instead, you can copy-paste answers and attribute their source. I will edit your answer to demonstrate.
    – wjandrea
    May 20, 2017 at 18:44
  • This is the right answer, though.
    – rjurney
    Sep 7, 2020 at 9:16

Because you use python 3, the right command would be pip3 install pydot graphviz. You can install pip3 using sudo apt install python3-pip.

  • 1
    or simply ln -s /path/to/pip3 /path/to/pip
    – 0 _
    Oct 25, 2017 at 9:59

On Ubuntu 17.10, the ff fixed the issue:

sudo apt-get install python3-pydot graphviz
sudo pip3 install pydot_ng

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .