简体   繁体   中英

Importing modules installed via Homebrew into Python

Installed graph-tool via homebrew using $ brew install graph-tool

Installation was successful. Now, when I try to import the module in the python shell, using from graph_tool.all import *

I receive a ModuleNotFoundError: No module named 'graph_tool' error

Python version info- Python 3.8.5 , installed via pyenv at /Users/aamodpant/.pyenv/shims/python

graph-tool installed in /usr/local/Cellar/graph-tool

How do I import this into my python program?

This looks like a very similar issue to the one in this post: How to let python3 import graph-tool installed by Homebrew?

Have a look at the top answer provided by NatKost where they created a symbolic link between graph-tool and the Python packages:

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

You should be able adapt this for your graph-tool install and your venv.

Check this site here and see whehter your problem is fixed. Alternatively, check this post here

I would recommend installing using pip .

Thanks @Robert Young, for leading me to the right post How to let python3 import graph-tool installed by Homebrew?

Because numpy and scipy are dependencies of graph-tool, they were installed automatically using home-brew when installing graph-tool.

After editing the command shown in the linked solution, I added a symbolic link between graph-tool and my python

ln -s /usr/local/Cellar/graph-tool/2.33/lib/python3.8/site-packages/graph_tool /Users/aamodpant/.pyenv/versions/3.8.5/lib/python3.8/site-packages

added similar links between numpy, scipy and python

ln -s /usr/local/Cellar/numpy/1.19.1/lib/python3.8/site-packages/numpy /Users/aamodpant/.pyenv/versions/3.8.5/lib/python3.8/site-packages
ln -s /usr/local/Cellar/scipy/1.5.2/lib/python3.8/site-packages/scipy /Users/aamodpant/.pyenv/versions/3.8.5/lib/python3.8/site-packages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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