欧博娱乐Install — PyGraphviz 1.9 documentation
PyGraphviz requires:
Note
These instructions assume you have Python and a C/C++ Compiler on your computer.
Warning
Do not use the default channels to install pygraphviz with conda. The conda-forge channel should be used instead:
conda install --channel conda-forge pygraphviz
We recommend installing Python packages using pip and virtual environments.
LinuxWe recommend installing Graphviz using your Linux system’s package manager. Below are examples for some popular distributions.
Ubuntu and Debian$ sudo apt-get install graphviz graphviz-dev $ pip install pygraphviz
Fedora and Red HatYou may need to replace dnf with yum in the example below.
$ sudo dnf install graphviz graphviz-devel $ pip install pygraphviz
macOSWe recommend installing Graphviz using the Homebrew package manager or MacPorts for macOS.
Homebrew$ brew install graphviz $ pip install pygraphviz
MacPorts$ port install graphviz $ pip install pygraphviz $ pip install --global-option=build_ext \ --global-option="-I/opt/local/include/" \ --global-option="-L/opt/local/lib/" \ pygraphviz
Advanced The two main difficulties areinstalling Graphviz and
informing pip where Graphviz is installed.
Providing path to Graphviz
If you’ve installed Graphviz and pip is unable to find Graphviz, then you need to provide pip with the path(s) where it can find Graphviz. To do this, you first need to figure out where the binary files, includes files, and library files for Graphviz are located on your file system.
Once you know where you’ve installed Graphviz, you will need to do something like the following. There is an additional example using Chocolatey on Windows further down the page.
WindowsHistorically, installing Graphviz and PyGraphviz on Windows has been challenging. Fortunately, the Graphviz developers are working to fix this and their recent releases have much improved the situation.
For this reason, PyGraphviz 1.7 only supports Graphviz 2.46.0 or higher on Windows. We recommend either manually installing the official binary release of Graphviz or using Chocolatey, which has been updated to Graphviz 2.46.0.
You may also need to install Visual C/C++, e.g. from here: https://visualstudio.microsoft.com/visual-cpp-build-tools/
Assuming you have Python and Visual C/C++ installed, we believe the following should work on Windows 10 (64 bit) using PowerShell.
Manual downloadDownload and install 2.46.0 for Windows 10 (64-bit): stable_windows_10_cmake_Release_x64_graphviz-install-2.46.0-win64.exe.
Install PyGraphviz via
PS C:\> python -m pip install --global-option=build_ext ` --global-option="-IC:\Program Files\Graphviz\include" ` --global-option="-LC:\Program Files\Graphviz\lib" ` pygraphviz
ChocolateyPS C:\> choco install graphviz PS C:\> python -m pip install --global-option=build_ext ` --global-option="-IC:\Program Files\Graphviz\include" ` --global-option="-LC:\Program Files\Graphviz\lib" ` pygraphviz
FAQ
Q
I followed the installation instructions but when I do: >>> import pygraphviz
I get an error like:
ImportError: libagraph.so.1: cannot open shared object file: No such file or directory
What is wrong?
ASome Unix systems don’t include the Graphviz library in the default search path for the run-time linker. The path is often something like /usr/lib/graphviz or /sw/lib/graphviz etc. and it needs to be added to your search path. On *nix systems, the preferred way to do this is by setting the appropriate flags when building/installing pygraphviz. For example, if the Graphviz libraries are installed in /opt/lib/mygviz/ on your system:
pip install --global-option=build_ext \ --global-option="-L/opt/lib/mygviz/" \ --global-option="-R/opt/lib/mygviz/" \ pygraphviz
In this example, the -L and -R flags tell the linker where to look for the required Graphviz libraries at build time and run time, respectively.
QHow do I compile pygraphviz under Windows?
ASee for the latest on how to install Graphviz and pygraphviz on Windows.
QWhy don’t you distribute a pygraphviz Windows installer?
AWe would very much like to make binary wheels available for pygraphviz, but there are several complications. pygraphviz is a wrapper around Graphviz, which means that Graphviz must be installed, and Graphviz header files, libraries and command line executables must all be accessible for the wrapper. The recommended use of the poses challenges for wheel packaging.
See also
This GitHub issue for further discussion on wheels and packaging.