bbopt / nomad

NOMAD - A blackbox optimization software
https://nomad-4-user-guide.readthedocs.io/
GNU Lesser General Public License v3.0
114 stars 24 forks source link

Install PyNomad in virtual environment #122

Open lucagrementieri opened 1 year ago

lucagrementieri commented 1 year ago

The current installation instructions make very hard to install PyNomad in virtual enviroment, in fact the --user option in the line COMMAND python setup_PyNomad.py ${CMAKE_BINARY_DIR} ${NOMAD_VERSION} install inside interfaces/PyNomad/CMakeLists.txt overwrite the default setting of a virtual environment.

A separate parameter PYTHON_DIR defined in CMake could allow the user to specify the correct Python location, otherwise the --user flag could be removed to let the system the best location by itself.

Is there a way to install PyNomad in a virtual environment with the current code?

jan-provaznik commented 1 year ago

To answer your question: If you need that, do not build the Python module with the rest of the project.

  1. Suppose we are dealing with the release 4.3.1.

  2. Follow the instructions for building and installing Nomad.

  3. Suppose it was built in /some/path/nomad-v.4.3.1 and installed into /some/path/nomad-v.4.3.1/build/release. Adjust these paths below to fit your situation.

  4. Navigate to /some/path/nomad-v.4.3.1/interfaces/PyNomad

  5. Compile the module manually. Suppose the root of the virtual environment is located at /another/path/to/venv. Execute

    /another/path/to/venv/bin/python setup_PyNomad.py /tmp/nomad-v.4.3.1/build/release "4.3.1" build_ext --inplace

    to compile the module. Please note that you'll need Cython available within that environment.

  6. Once the module is compiled, execute

    /another/path/to/venv/bin/python setup_PyNomad.py /tmp/nomad-v.4.3.1/build/release 4.3.1 install --

    to install it within the virtual environment.

ctribes commented 1 year ago

Thanks for the suggestion. It works for me in a virtual environment.

davidmurray commented 1 year ago

I would just like to point out that in my case, I had to do this: export LD_LIBRARY_PATH=$NOMAD_HOME/build/release/lib64/:$LD_LIBRARY_PATH Otherwise I got the following error:

$ python runTest_BlockEval.py 
Traceback (most recent call last):
  File "/.../.../runTest_BlockEval.py", line 1, in <module>
    import PyNomad
ImportError: libnomadUtils.so.4.3: cannot open shared object file: No such file or directory