简体   繁体   English

如何让Homebrew安装python3导入图形工具?

[英]How to let python3 import graph-tool installed by Homebrew?

I tried to use Homebrew to install graph-tool , but the python3 cannot find it. 我试图使用Homebrew来安装graph-tool ,但python3找不到它。

    brew tap homebrew/science
    brew install graph-tool

It is said that the package is installed in homebrew/science/graph-tool-2.22_1 , where I only found /usr/local/Homebrew/Library/Taps/homebrew/homebrew-science/graph-tool.rb . 据说该软件包安装在homebrew/science/graph-tool-2.22_1 ,我只找到了/usr/local/Homebrew/Library/Taps/homebrew/homebrew-science/graph-tool.rb

When I tried to import graph-tool in python3, it shows that from graph_tool.all import * ImportError: No module named 'graph_tool' 当我尝试在python3中导入图形工具时,它显示from graph_tool.all import * ImportError: No module named 'graph_tool'

I am using python3. 我正在使用python3。

which python3 /usr/local/bin/python3

Is there a way I can use the graph_tool package installed in Homebrew? 有没有办法可以使用Homebrew中安装的graph_tool包?

Any help would be appreciated. 任何帮助,将不胜感激。

另一个对我有用的解决方案就是创建一个从graph-tool到python side包的符号链接

ln -s /usr/local/Cellar/graph-tool/2.26_2/lib/python3.6/site-packages/graph_tool /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages

A quick solution. 快速解决方案。

To Check brew installed package path in the console, 要在控制台中检查brew安装的包路径,

brew --prefix graph-tool

Then at the beginning of the code, append the path. 然后在代码的开头添加路径。

    import sys
    sys.path.append('/usr/local/Cellar/graph-tool/2.22_1/lib/python2.7/site-packages/')
    from graph_tool.all import *

The way it supposed to work is with passing --with-python3 to brew: 它应该工作的方式是将--with-python3传递给brew:

brew install graph-tool --with-python3

But it causes rebuild of graph-tool and need of matplotlib, numpy and scipy from brew instead pip which is not very appealing specially as the recent stable version networkx is not yet compatible with matplotlib (fixed on master) so I'd rather to go with this: 但它导致图形工具的重建和需要matplotlib,numpy和scipy来自brew而不是pip,这不是特别吸引人,因为最近的稳定版本networkx还不兼容matplotlib(固定在master上)所以我宁愿去有了这个:

brew install graph-tool --with-python3 --without-matplotlib --without-numpy --without-scipy

which tells the formula to not seek for brew installed matplotlib/numpy/scipy. 这告诉公式不要寻求brew安装matplotlib / numpy / scipy。

And for some reasons I couldn't use the formula with python2 support, which I didn't care, so I ended up with: 由于某些原因,我不能使用python2支持的公式,我不在乎,所以我最终得到:

brew install graph-tool --without-python --with-python3 --without-matplotlib --without-numpy --without-scipy

I was in a virtualenv when this happened to me. 当我遇到这种情况时,我正处于一种虚拟状态。 Make sure homebrew installs graph-tool with the same python version you want to use for your virtualenv, then recreating the virtualenv with --system-site-packages will allow it to access system packages, including graph-tool installed through homebrew. 确保自制软件安装图形工具与您想要用于virtualenv的相同python版本,然后使用--system-site-packages重新创建virtualenv将允许它访问系统软件包,包括通过自制软件安装的图形工具。

See: https://github.com/Homebrew/homebrew-science/issues/5741 请参阅: https//github.com/Homebrew/homebrew-science/issues/5741

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM