schrodinger / pymol-open-source

Open-source foundation of the user-sponsored PyMOL molecular visualization system.
https://pymol.org/
Other
1.14k stars 271 forks source link

setup.py ignoring library search environment variables. #287

Open ErikPoppleton opened 1 year ago

ErikPoppleton commented 1 year ago

In the installation instructions it says:

Environment variables: PREFIX_PATH Colon-delimited list of paths to search for headers and libraries, e.g. $HOME/mmtf-cpp:$HOME/msgpack-c:/opt/local CXX C++ compiler command CC C compiler command CXXFLAGS C++ compiler flags CFLAGS C compiler and linker flags CPPFLAGS C/C++ preprocessor flags, e.g. -I/tmp/msgpack-c/include LDFLAGS linker flags

I have many of the libraries required in $HOME/.local/include due to not having admin privileges on my computer. So I set:

PREFIX_PATH=$HOME/.local/include:/Users/erikpoppleton/.local/lib
CFLAGS=-I$HOME/.local/include
CXXFLAGS=-I$HOME/.local/include

In addition to having this directory on my $PATH itself.

However pymol's setup.py completely ignores these when I try to run it and I get a bunch of 'X.h' file not found errors.

contrib/uiuc/plugins/molfile_plugin/src/netcdfplugin.c:27:10: fatal error: 'netcdf.h' file not found
layer0/os_gl.h:23:10: fatal error: 'GL/glew.h' file not found
layer1/Ray.h:22:10: fatal error: 'glm/glm.hpp' file not found

Despite these files being in the directory specified in the environment variables:

% find ~/.local  \( -name netcdf.h -o -name glew.h -o -name glm.hpp \) 
~/.local/include/GL/glew.h
~/.local/include/netcdf.h
~/.local/include/glm/glm.hpp

Same problem with linking the actual libraries which are in ~/.local/lib/ if I move the header files into the directory which wants them.

This is on MacOS 13.0.1 and an up-to-date pull from the master branch of this repository.

UPDATE:
It does work if I run build-ext and specify the include and library paths followed by install and then re-link the binary.

python setup.py build_ext --include-dirs=$HOME/.local/include --library-dirs=$HOME/.local/lib
python setup.py install --prefix=$HOME/.local
install_name_tool -delete_rpath $HOME/miniconda3/lib $HOME/.local/lib/python3.11/site-packages/pymol/_cmd.cpython-311-darwin.so
install_name_tool -delete_rpath $HOME/miniconda3/lib $HOME/.local/lib/python3.11/site-packages/pymol/_cmd.cpython-311-darwin.so
install_name_tool -add_rpath $HOME/.local/lib $HOME/.local/lib/python3.11/site-packages/pymol/_cmd.cpython-311-darwin.so

Might be beneficial to add this to the INSTALL notes.

speleo3 commented 1 year ago

Have you tried PREFIX_PATH=$HOME/.local?

ErikPoppleton commented 1 year ago

It then finds it during installation, but the libraries cannot be loaded at runtime without relinking.

Traceback (most recent call last):
  File "$HOME/.local/lib/python3.11/site-packages/pymol/__init__.py", line 72, in <module>
    import pymol
  File "$HOME/.local/lib/python3.11/site-packages/pymol/__init__.py", line 558, in <module>
    import pymol._cmd
ImportError: dlopen($HOME/.local/lib/python3.11/site-packages/pymol/_cmd.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libGLEW.2.2.dylib

It then works if I run the install_name_tool commands I listed in my earlier post.