As most Mac users, I have two separate versions of python on my machine: The one installed by Apple (version 3.9 in /usr/bin) and one installed via Homebrew (version 3.11 in /opt/homebrew/bin).
I've put the latter first in path and, sure enough,
which python3
prints
/opt/homebrew/bin/python3
and
python3 --version
prints
Python 3.11.6
but Mojo seems to use the other version, as packages installed via pip3 are not accessible.
The following sys_path.
from python import Python
def main():
let sys = Python.import_module("sys")
print(sys.prefix)
prints
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9
How do I make Mojo use the correct python lib?
I've found not one but two possible solutions:
~/.modular/modular.cfg, in groupmojofindpython_liband set it to the path to the python lib installed with homebrew. In my case I've had to changeto
EXPORTingMOJO_PYTHON_LIBRARYwith the correct path will override the config setting for the current session. I've putin my
~/.zshrc. Don't forget tosourceor restart the terminal when using the rc file.The second option comes in handy, if you want to test against different versions of the python lib.