我尝试使用Homebrew来安装graph-tool,但是python3找不到它。
brew tap homebrew/science
brew install graph-tool
据说该软件包安装在homebrew/science/graph-tool-2.22_1
,我只找到/usr/local/Homebrew/Library/Taps/homebrew/homebrew-science/graph-tool.rb
。
当我尝试在python3中导入图形工具时,它显示了这一点
from graph_tool.all import *
ImportError: No module named 'graph_tool'
我正在使用python3。
which python3
/usr/local/bin/python3
有没有办法可以使用Homebrew中安装的graph_tool包?
任何帮助都将不胜感激。
答案 0 :(得分:4)
另一个对我有用的解决方案就是创建一个从graph-tool到python side packages的符号链接
__lsan_do_leak_check
答案 1 :(得分:0)
快速解决方案。
要在控制台中检查brew安装的包路径,
brew --prefix graph-tool
然后在代码的开头,追加路径。
import sys
sys.path.append('/usr/local/Cellar/graph-tool/2.22_1/lib/python2.7/site-packages/')
from graph_tool.all import *
答案 2 :(得分:0)
它应该工作的方式是将--with-python3传递给brew:
brew install graph-tool --with-python3
但它导致图形工具的重建和需要matplotlib,numpy和scipy来自brew而不是pip,这不是特别吸引人,因为最近的稳定版本networkx还不兼容matplotlib(固定在master上)所以我&#39 ; d宁愿这样做:
brew install graph-tool --with-python3 --without-matplotlib --without-numpy --without-scipy
告诉the formula不要求brew安装matplotlib / numpy / scipy。
由于某些原因,我无法使用python2支持的公式,我并不关心,所以我最终得到了:
brew install graph-tool --without-python --with-python3 --without-matplotlib --without-numpy --without-scipy
答案 3 :(得分:0)
这件事发生在我身上时,我正在一个虚拟环境中。确保homebrew使用与您的virtualenv相同的python版本安装了graph-tool,然后使用--system-site-packages
重新创建virtualenv将允许它访问系统软件包,包括通过homebrew安装的graph-tool。
请参阅:https://github.com/Homebrew/homebrew-science/issues/5741