SoarGroup / Soar

Soar, a general cognitive architecture for systems that exhibit intelligent behavior.
http://soar.eecs.umich.edu
Other
333 stars 72 forks source link

Python SML client uses hard-coded Python library path #504

Open analog-cbarber opened 1 month ago

analog-cbarber commented 1 month ago

I downloaded the 9.6.3 distribution and ran setup.sh on a Mac M1. When I tried to import the SML client package, I got this error:

(soar) SoarSuite/bin % python
Python 3.12.6 | packaged by conda-forge | (main, Sep 22 2024, 14:07:06) [Clang 17.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Python_sml_ClientInterface
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Christopher.Barber/SoarSuite_9.6.3-Multiplatform/bin/Python_sml_ClientInterface.py", line 12, in <module>
    import _Python_sml_ClientInterface
ImportError: dlopen(/Users/Christopher.Barber/SoarSuite_9.6.3-Multiplatform/bin/_Python_sml_ClientInterface.so, 0x0002): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.12/Python
  Referenced from: <08B46C96-24A4-3078-88D3-8A62B481CFC4> /Users/Christopher.Barber/SoarSuite_9.6.3-Multiplatform/bin/_Python_sml_ClientInterface.so
  Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file), '/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file)

It looks like it is assuming that Python 3.12 has been installed using the public Python installer, but it is actually common for people to install python using other tools that put it in other places. In my case, it is installed in a specific conda environment.

Not sure if there is an environment variable I can set to fix this or if I have to just build it myself.

Ideally, the code should not use any hard coded paths and instead should get the location of the Python library from the python process doing the import.

It would also be useful if the download explicitly specified which version of python it was compiled for.

analog-cbarber commented 1 month ago

One workaround is to use the install_name_tool to rewrite the location of the python executable to the one you are using, e.g.:

$ install_name_tool -change /Library/Frameworks/Python.framework/Versions/3.12/Python /Users/jdoe/miniforge3/bin/python _Python_sml_ClientInterface.so

Perhaps this could be done in the setup.sh script using which python to find the executable?