在 Windows 上安装 PygraphViz,Python 2.6

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2798858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:25:45  来源:igfitidea点击:

Installing PygraphViz on Windows, Python 2.6

pythoncwindowsinstallationgraphviz

提问by jbochi

Anybody out there has successfully installed PygraphViz on Windows?

有人在 Windows 上成功安装了 PygraphViz 吗?

Since there is not an official release for Windows, I'm trying to build it myself, but it fails to compile. I'm not the first oneto face this issue, but I could not find an answer.

由于没有Windows的正式版本,我正在尝试自己构建它,但它无法编译。我不是第一个面对这个问题,但我无法找到答案。

This is the console output:

这是控制台输出:

C:\Python26\Lib\site-packages\pygraphviz-0.99.1>c:\python26\python.exe setup.py
install
library_path=C:/Program Files/Graphviz2.26.3/lib/debug/dll
include_path=C:/Program Files/Graphviz2.26.3/include/graphviz
running install
running build
running build_py
running build_ext
building 'pygraphviz._graphviz' extension
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
3 /GS- /DNDEBUG "-IC:/Program Files/Graphviz2.26.3/include/graphviz" -Ic:\python
26\include -Ic:\python26\PC /Tcpygraphviz/graphviz_wrap.c /Fobuild\temp.win32-2.
6\Release\pygraphviz/graphviz_wrap.obj
graphviz_wrap.c
warning: I don't know what to do with 'runtime_library_dirs': ['C:/Program Files
/Graphviz2.26.3/lib/debug/dll']
error: don't know how to set runtime library search path for MSVC++

Any help would be appreciated!

任何帮助,将不胜感激!

采纳答案by Andrew Filev

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

这是在 Python 2.7 中对我有用的内容。我认为它应该在 Python 2.6 中类似地工作。前提条件:安装 mingw32(如果您正在使用它,则包含在 pythonxy distrib 中),Graphviz

1) Download pygraphviz sources

1)下载pygraphviz源

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

2) 编辑 setup.py 以将路径更改为 smth 之类的

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.

请注意,它是 \bin,而不是 \lib。与库链接对我不起作用。

3) run python setup.py build -c mingw32

3)运行 python setup.py build -c mingw32

Result of step 3:

第 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

4) 将刚刚构建的 lib.win32-2.7(名为 的单个子文件夹)的结果复制pygraphviz到 Python 的 site-packages 文件夹中

Enjoy!

享受!

回答by geotheory

I appreciate this may be an obsolete thread by now, but to update it for others currently hitting this wall, the installer at Christoph Gohlke's Unofficial Windows Binaries for Python Extension Packageshas just worked for me..

我很欣赏这现在可能是一个过时的线程,但是要为当前遇到此问题的其他人更新它,Christoph Gohlke 的非官方 Python 扩展包的 Windows 二进制文件的安装程序刚刚对我来说有效..

回答by Eli Bendersky

I've just ran into the same problem myself today. It isn't much of an answer, but I read in their FAQ:

今天我自己也遇到了同样的问题。这不是一个很好的答案,但我在他们的常见问题解答中读到:

Q:

How do I compile pygraphviz under Windows? And why don't you distribute a pygraphviz Windows installer?

A:

We don't have Windows development machines but would like to have pygraphviz work on all platforms. If you have success with Windows or would be willing to help test and distribute a Windows installer please drop us a note.

See also ticket 67: https://networkx.lanl.gov/ticket/67

问:

如何在Windows下编译pygraphviz?为什么不分发 pygraphviz Windows 安装程序?

A:

我们没有 Windows 开发机器,但希望 pygraphviz 可以在所有平台上运行。如果您在 Windows 上取得了成功,或者愿意帮助测试和分发 Windows 安装程序,请给我们留言。

另请参阅票证 67:https: //networkx.lanl.gov/ticket/67

This, together with multiple unanswered pleas for help on various forums, mailing lists and newsgroups, lead me to believe that running PyGraphviz on Windows isn't something that can be done simply today.

这一点,再加上各种论坛、邮件列表和新闻组上的多个未答复的求助请求,让我相信在 Windows 上运行 PyGraphviz 不是今天可以简单完成的事情。

So I did the next obvious thing (*) and fired up my Ubuntu on top of VirtualBox to create Graphviz graphs with Python. Curiously, it fails to install from source on Ubuntu as well, unless you have Graphviz itself installed from source, but it can be installed from a pre-built package with sudo apt-get python-pygraphviz.

所以我做了下一件显而易见的事情 (*) 并在 VirtualBox 上启动我的 Ubuntu 以使用 Python 创建 Graphviz 图。奇怪的是,它也无法在 Ubuntu 上从源代码安装,除非您从源代码安装了 Graphviz,但它可以从带有sudo apt-get python-pygraphviz.

So now I'm a happy pygraphviz user. Or at least 90% happy. PGV shows a os.popen3deprecation warning on Python 2.6, and a 18-month-old ticketwith a patch on this issue still hasn't been incorporated. Argh!

所以现在我是一个快乐的 pygraphviz 用户。或者至少 90% 快乐。PGVos.popen3在 Python 2.6 上显示了一个弃用警告,并且一个18 个月前的票证仍然没有包含一个关于这个问题的补丁。啊!

(*) I do it more and more lately...

(*) 我最近越来越这样做了......

回答by WombatPM

If you remove the 'runtime_library_dirs' parameter from the extensiondictionary in on line 147 in setup.py, your error message goes away. However, it can't find cgraph.lib. If you change your settings to

如果您从setup.py 的第 147 行的扩展字典中删除“runtime_library_dirs”参数,您的错误消息就会消失。但是,它找不到 cgraph.lib。如果您将设置更改为

library_path=r'C:\Program Files\Graphviz2.26.3\lib\debug\lib'

everything complies and installs. You can import the modules, but the moment you try and access anything, it bombs out. In looking at the source for GraphViz, it appears that the windows version is C#/.NET - perhaps that is the source of our problems?

一切都符合并安装。您可以导入模块,但是当您尝试访问任何内容时,它就会爆炸。在查看 GraphViz 的源代码时,似乎 Windows 版本是 C#/.NET - 也许这就是我们问题的根源?

回答by sdfgsdfsdfg

Hat the same problem and I finally got it to work! The problem was actually in Python's msvc9compiler.py (yes you do need VS8's vc9 to compile, too). The error comes on line 698 in the function runtime_library_dir_option(). Instead of having it throw an error, have it return the same string as library_dir_option():

遇到同样的问题,我终于让它工作了!问题实际上出在 Python 的 msvc9compiler.py 中(是的,你也需要 VS8 的 vc9 来编译)。错误出现在函数 runtime_library_dir_option() 的第 698 行。不要让它抛出错误,而是让它返回与 library_dir_option() 相同的字符串:

def runtime_library_dir_option(self, dir):
    return "/LIBPATH:" + dir

Then compile and it should work.

然后编译,它应该可以工作。

回答by jur

I managed to compile pygraphviz under windows with the following setup:

我设法使用以下设置在 windows 下编译 pygraphviz:

Windows 7, WinPython-32bit-2.7.6.3, Graphviz2.38, microsoft visual c++ 2008 express edition, pygraphvize 1.3 dev

Windows 7, WinPython-32bit-2.7.6.3, Graphviz2.38, microsoft visual c++ 2008 express edition, pygraphvize 1.3 dev

in setup.py changed lines 35 and 36 to:

在 setup.py 中将第 35 和 36 行更改为:

include_dirs = r"C:\Program Files\Graphviz2.38\include" library_dirs = r"C:\Program Files\Graphviz2.38\lib\release\lib"

include_dirs = r"C:\Program Files\Graphviz2.38\include" library_dirs = r"C:\Program Files\Graphviz2.38\lib\release\lib"

The compilation works and you get a working pygraphviz python module.

编译有效,您将获得一个有效的 pygraphviz python 模块。

Hopes this helps.

希望这会有所帮助。

回答by Huaidong Xiong

This works for me, Python 2.7 32 bit, PyGraphViz 2.38, VCForPython27, Windows 10 64 bit.

这对我有用,Python 2.7 32 位,PyGraphViz 2.38,VCForPython27,Windows 10 64 位。

First, install VCForPython27, see http://aka.ms/vcpython27.

首先,安装 VCForPython27,参见http://aka.ms/vcpython27

Then, execute the following command, so that distutils.msvc9compilercan find the VC compiler. (This needs Administrator privilege. And if your Windows is 32 bit, you need to adjust the registry key.)

然后,执行下面的命令,这样就distutils.msvc9compiler可以找到VC编译器了。(这需要管理员权限。如果您的 Windows 是 32 位,则需要调整注册表项。)

reg add HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio.0\Setup\VC -v productdir -t REG_SZ -d "%LocalAppData%\Programs\Common\Microsoft\Visual C++ for Python.0" -f

Finally, install PyGraphViz.

最后,安装 PyGraphViz。

set INCLUDE=C:\Program Files (x86)\Graphviz2.38\include
set LIB=C:\Program Files (x86)\Graphviz2.38\lib\release\lib
pip install pygraphviz

回答by jdgjdg

Alternately, you can try to use easy_installand avoid compiling. I installed "distribute", a fork of easy_install. But it also requires pkg-config, and you either have to compile that or get an older version. Furthermore, you also have to add pkg-config to the application path.

或者,您可以尝试使用easy_install并避免编译。我安装了“distribute”,它是easy_install 的一个分支。但它也需要 pkg-config,你要么必须编译它,要么得到一个旧版本。此外,您还必须将 pkg-config 添加到应用程序路径中。