Installing Pygraphviz on Windows 10 64-Bit, Python 3.6

howto install pygraphviz on windows 10 64bit

Start reading from here
https://github.com/pygraphviz/pygraphviz/issues/58

At the bottom of that page there is a link to a x64 zip file in Github (like this)
Unpack that. Create a coresponding Program Files folder for your x64 file and put them there

Then install using this

pip install --global-option=build_ext --global-option="-IC:\Program Files\Graphviz2.38\include" --global-option="-LC:\Program Files\Graphviz2.38\lib\" pygraphviz

How to install a package for a specific Python version on Windows 10?

The golden rule when one wants to access one of the multiple software versions (applies to any software (other than Python), on any OS) existing on a machine: use absolute paths.

There are multiple ways of pip installing (especially when involving VEnvs):

  1. Run PIP directly - most frequently used:

    pip install --upgrade pyaudio
  2. Run python -m pip:

    python -m pip install --upgrade pyaudio
  3. Run other convenience wrappers (Py (Win specific): [Python.Docs]: Using Python on Windows - From the command-line):

    py -3.6 -m pip install --upgrade pyaudio

But the form that I prefer (as it will always work - because it doesn't rely on environment variables like PATH), is the 2nd one:

"${PATH_TO_YOUR_PYTHON_3_6}" -m pip install --upgrade pyaudio

where ${PATH_TO_YOUR_PYTHON_3_6} is just a placeholder for the actual Python 3.6 executable path (e.g. %ProgramFiles%\Python 3.6\python.exe).

Note that this works fine (end easy) when having multiple Python versions installed (custom built, VEnvs, ...).

Check [Python.Docs]: Using Python on Windows - Installing Without UI for more details regarding install paths.

Generalizing:

"${PATH_TO_PYTHON_EXECUTABLE}" -m pip install ${PACKAGE_NAME}

where ${PACKAGE_NAME} is (obviously) the package name.

Note that sometimes, due to special conditions (like local PIP repositories configuration, ...), the installation would have to be done in 2 steps:

  1. Download the .whl locally

  2. Pass it to PIP (in order to install it)

as described in [SO]: Installing pygraphviz on Windows 10 64-bit, Python 3.6 (@CristiFati's answer) (Shortcut section (somewhere at the end)).

${PATH_TO_PYTHON_EXECUTABLE} (using v3.9 as an example) can be (from my machines):

  • Win:

    • %ProgramFiles%\Python 3.9\python.exe

    • E:\Work\Dev\VEnvs\py_pc064_03.09_test0\Scripts\python.exe

    • F:\Install\pc064\Anaconda\Anaconda\Version\python.exe

  • Nix:

    • /usr/bin/python3.9

    • /opt/qti-aic/dev/python/qaic-env/bin/python

When not sure about an executable location (actually not limited to executables), that can be checked:

  • Win: [MS.Docs]: where (where /?)

  • Nix: [Die.Linux]: which(1) (man which).

    Worth mentioning aliases: [Man7]: ALIAS(1P) (man alias)

Might also worth reading:

  • [SO]: PyCharm doesn't recognize installed module (@CristiFati's answer)

  • [SO]: How to update pywin32 automatically? (@CristiFati's answer)

  • [SO]: PyAudio.write SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats (@CristiFati's answer)

Installing PygraphViz on Windows, Python 2.6

Here's what worked for me in Python 2.7. I assume it should work similarly in Python 2.6.
Precondition: Install mingw32 (included in pythonxy distrib if you're using it), Graphviz

1) Download pygraphviz sources

2) Edit setup.py to change paths to smth like

library_path=r"c:\Program Files (x86)\Graphviz 2.28\bin"
include_path=r"c:\Program Files (x86)\Graphviz 2.28\include\graphviz"

Note that it's \bin, not \lib. Linking with libs didn't work for me.

3) run python setup.py build -c mingw32

Result of step 3:

c:\Python27\Lib\site-packages\pygraphviz-1.1>python setup.py build -c mingw32
library_path=c:\Program Files (x86)\Graphviz 2.28\bin
include_path=c:\Program Files (x86)\Graphviz 2.28\include\graphviz
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\MinGW32-xy\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ic:\Program Files (x86)\G
raphviz 2.28\include\graphviz" -Ic:\Python27\include -Ic:\Python27\PC -c pygraph
viz/graphviz_wrap.c -o build\temp.win32-2.7\Release\pygraphviz\graphviz_wrap.o
pygraphviz/graphviz_wrap.c: In function 'agattr_label':
pygraphviz/graphviz_wrap.c:2855:5: warning: return makes integer from pointer wi
thout a cast
writing build\temp.win32-2.7\Release\pygraphviz\_graphviz.def
C:\MinGW32-xy\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\py
graphviz\graphviz_wrap.o build\temp.win32-2.7\Release\pygraphviz\_graphviz.def "
-Lc:\Program Files (x86)\Graphviz 2.28\bin" -Lc:\Python27\libs -Lc:\Python27\PCb
uild "-Wl,-Rc:\Program Files (x86)\Graphviz 2.28\bin" -lcgraph -lcdt -lpython27
-lmsvcr90 -o build\lib.win32-2.7\pygraphviz\_graphviz.pyd

4) copy the result from the just built lib.win32-2.7 (single sub-folder called pygraphviz) into your Python's site-packages folder

Enjoy!



Related Topics



Leave a reply



Submit