Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mojo] Exception: Could not find libpython. #706

Closed
Junital opened this issue Sep 10, 2023 · 9 comments
Closed

[Mojo] Exception: Could not find libpython. #706

Junital opened this issue Sep 10, 2023 · 9 comments
Labels
mojo-repo Tag all issues with this label

Comments

@Junital
Copy link

Junital commented Sep 10, 2023

Environment: Windows WSL

When I run modular install mojo, it occurs an error of no libpython, I try many ways to change $LD_LIBRARY_PATH, but the error isn't fixed.

Here are detailed errror:

Traceback (most recent call last):
  File "/home/junital/.modular/pkg/packages.modular.com_mojo/scripts/post-install/pick_python.py", line 67, in <module>
    main()
  File "/home/junital/.modular/pkg/packages.modular.com_mojo/scripts/post-install/pick_python.py", line 50, in main
    raise Exception(
Exception: Could not find libpython. Check your Python installation and ensure that $LD_LIBRARY_PATH includes the location to the installed Python library (e.g. /usr/lib/x86_64-linux-gnu).
@manojmanivannan
Copy link

Facing same issue

@ematejska ematejska added the modular-cli modular tool issues label Sep 11, 2023
@jackos
Copy link
Collaborator

jackos commented Sep 11, 2023

Hi do a search on your system for libpython:

sudo find / -name 'libpython*.so'

For example this might show up amongst others:

/opt/conda/lib/libpython3.10.so
/opt/conda/lib/libpython3.so

So before installing the cli you can add the directory that libpython*.so was in:

export LD_LIBRARY_PATH="/opt/conda/lib:$LD_LIBRARY_PATH"

Now after install you'll find in ~/.modular/modular.cfg there will be a key:

python_lib = /opt/conda/lib/libpython3.10.so

Which you can change after install if you like.

@Junital
Copy link
Author

Junital commented Sep 15, 2023

Sorry but here are still some issues:
When I try to find libpython:

sudo find / -name 'libpython*.so'

Here is my result:

/usr/lib/x86_64-linux-gnu/libpython3.10.so
/usr/lib/python3.10/config-3.10-x86_64-linux-gnu/libpython3.10.so

My LD_LIBRARY_PATH:

echo $LD_LIBRARY_PATH
/usr/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu/

But when I install mojo, the issue isn't fixed.

Here are some clues:

python3.10 /home/junital/.modular/pkg/packages.modular.com_mojo/scripts/post-install/pick_python.py
ModuleNotFoundError: No module named 'find_libpython'
python3.9 /home/junital/.modular/pkg/packages.modular.com_mojo/scripts/post-install/pick_python.py
Exception: Could not find libpython. Check your Python installation and ensure that $LD_LIBRARY_PATH includes the location to the installed Python library (e.g. /usr/lib/x86_64-linux-gnu).

I think it uses python3.9 to run the code instead of python3.10.

@smuniraj2018 smuniraj2018 removed the modular-cli modular tool issues label Sep 16, 2023
@smuniraj2018 smuniraj2018 changed the title Exception: Could not find libpython. [Mojo] Exception: Could not find libpython. Sep 16, 2023
@BTripp1986
Copy link

I ran into this issue while using pyenv. I resolved it by installing an updated python version using PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v 3.11.5 and then activating that as my global pyenv version.

After installing that version I installed mojo with LD_LIBRARY_PATH="~/.pyenv/versions/3.11.5/lib/" but that may or may not have been necessary.

I hope this helps anyone who runs into this issue while using pyenv.

@sejkimm
Copy link

sejkimm commented Oct 20, 2023

I faced the same error on M2 Mac with macOS 14.0.
Changing global pyenv from 3.9 into 3.11 using PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v 3.11.3,
solved it too.
Thanks @BTripp1986!

@PaulBFB
Copy link

PaulBFB commented Oct 30, 2023

quick confirmation here, the other approaches did not work for me (setting the key in ~/.modular/modular.cfg )
what did work:

  • update: PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v 3.11.5
  • activate global: pyenv global 3.11.5
  • set library path: LD_LIBRARY_PATH="/Users/[USERNAME]/.pyenv/versions/3.11.5/lib"
  • clean and install: modular clean && modular install mojo

thanks!

@robertbcalhoun
Copy link

Current versions of python (3.11, 3.12) compiled under linux default to building a static (.a) rather than shared (.so) version of libpython. Rebuilding after ./configure --enable-shared builds libpython3.so but neither the mojo installer nor python itself could find the library in the default install location of /usr/local/lib.

Setting LD_LIBRARY_PATH did not help, but per this SO question adding /usr/local/lib to /etc/ld.so.conf and running sudo ldconfig resolved the linkage issue for both python and the mojo installer. (Probably this could have been avoided by using the correct configure option for shared library paths.)

@pbadeer
Copy link

pbadeer commented Feb 11, 2024

I ran into this issue while using pyenv. I resolved it by installing an updated python version using PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v 3.11.5 and then activating that as my global pyenv version.

After installing that version I installed mojo with LD_LIBRARY_PATH="~/.pyenv/versions/3.11.5/lib/" but that may or may not have been necessary.

I hope this helps anyone who runs into this issue while using pyenv.

This helped, but what did it for me was running modular clean before retrying my install.

@jackos
Copy link
Collaborator

jackos commented Jun 6, 2024

Resolved by b677622. Mojo now finds libpython using the python executable on the top of PATH.

Please try again with modular install mojo or modular install max, if it still fails try running the script in https://modul.ar/fix-python, if you don't have a compatible python on PATH, you can install conda using that same guide.

@jackos jackos closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

10 participants