Search code examples
pythonwindowspycharm

Problem importing dsplot library in Pycharm


I am exploring tree plots with the following library and code:

from dsplot.graph import Graph

graph = Graph(
    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []}, directed=True
)
graph.plot()

When I run the code, I get the following error:

from dsplot.graph import Graph
ModuleNotFoundError: No module named 'dsplot'

I have tried pip installing the dsplot library with this command on the PyCharm terminal:

pip install dsplot

But this then causes another error:

    Collecting dsplot
  Using cached dsplot-0.9.0-py3-none-any.whl (8.8 kB)
Collecting pygraphviz<2.0,>=1.7
  Using cached pygraphviz-1.12.tar.gz (104 kB)
  ERROR: Error [WinError 3] The system cannot find the path specified while executing command pip subprocess to install build dependencies
  Installing build dependencies ... error
ERROR: Could not install packages due to an OSError: [WinError 3] The system cannot find the path specified

What is the reason for this problem installing the library and how can I resolve it?


Solution

  • It looks like you have not installed pygraphviz.

    Install pygraphviz

    Try downloading it from their official website and make sure its added to your path by clicking "Add Graphviz to the System PATH for the current user". In your terminal, run dot -V and if it outputs your version of pygraphviz, you should be all set to run pip install dsplot.

    If dot -V does not return the Version:

    Make sure you checked this box during installation:

    enter image description here

    If you checked the box and it is still not in your PATH:

    1. Find where Graphviz is installed; it is likely in "C:\Program Files\Graphviz" but is dependent on installation and OS. Click on this directory, and right click on "bin" to copy the path.
    2. Open Start Search, type "env", and select "Edit the system environment variables".
    3. Click "Environment Variables" in System Properties
    4. Find "Path Variables" under "System Variables" and select "Edit"
    5. Click "New"
    6. Paste in the path of Graphviz, which is likely something like C:\Program Files\Graphviz\bin
    7. Click "Ok" on all open windows to apply the changes

    After adding Graphviz to your path, open a terminal and once again try dot -V. If that returns the version, then you should be able to run pip install dsplot.